* Makefile.in, configure.in, configure,
[fw/sdcc] / src / SDCCval.h
index 5160ddd23129920ff0181afa9a1b68a14d67791c..61217835db23848e3b47236efe06e4d959df406a 100644 (file)
@@ -6,19 +6,19 @@
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
-  
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-  
+
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-  
+
   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
-  what you give them.   Help stamp out software-hoarding!  
+  what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 #ifndef SDCCVAL_H
 #define SDCCVAL_H
 -------------------------------------------------------------------------*/
 #ifndef SDCCVAL_H
 #define SDCCVAL_H
 
 
 /* double to unsigned long conversion */
 
 
 /* double to unsigned long conversion */
-#define double2ul(val)  (((val) < 0) ? (unsigned long) -((long) -(val)) : (unsigned long) (val))
+/*
+ * See ISO/IEC 9899, chapter 6.3.1.4 Real floating and integer:
+ * If the value of the integral part cannot be represented by the integer type, the behavior is undefined.
+ * This shows up on Mac OS X i386 platform which useus SSE unit instead of the x87 FPU for floating-point operations
+ */
+/*
+ * on Mac OS X ppc (long) 2147483648.0 equals to 2147483647, so we explicitely convert it to 0x80000000
+ * on other known platforms (long) 2147483648.0 equals to -2147483648
+ */
+#define double2ul(val)  (((val) < 0) ? (((val) < -2147483647.0) ? 0x80000000UL : (unsigned long) -((long) -(val))) : (unsigned long) (val))
 
 /* value wrapper */
 typedef struct value
 
 /* value wrapper */
 typedef struct value
@@ -38,7 +47,6 @@ typedef struct value
     symbol *sym;                  /* Original Symbol                  */
     struct value *next;           /* used in initializer list         */
     unsigned vArgs:1;             /* arg list ended with variable arg */
     symbol *sym;                  /* Original Symbol                  */
     struct value *next;           /* used in initializer list         */
     unsigned vArgs:1;             /* arg list ended with variable arg */
-
   }
 value;
 
   }
 value;
 
@@ -49,7 +57,6 @@ typedef struct literalList
     struct literalList *next;
 } literalList;
 
     struct literalList *next;
 } literalList;
 
-
 enum
   {
     INIT_NODE,
 enum
   {
     INIT_NODE,
@@ -87,9 +94,9 @@ CCR_RESULT;
 #define  IS_VARG(x)             (x->vArgs)
 
 /* forward definitions for the symbol table related functions */
 #define  IS_VARG(x)             (x->vArgs)
 
 /* forward definitions for the symbol table related functions */
-void initValue ();
-value *newValue ();
+value *newValue (void);
 value *constVal (const char *);
 value *constVal (const char *);
+value *constCharVal (unsigned char);
 value *reverseVal (value *);
 value *reverseValWithType (value *);
 value *copyValue (value *);
 value *reverseVal (value *);
 value *reverseValWithType (value *);
 value *copyValue (value *);
@@ -131,13 +138,13 @@ value *list2val (initList *);
 struct ast *list2expr (initList *);
 void resolveIvalSym (initList *, sym_link *);
 value *valFromType (sym_link *);
 struct ast *list2expr (initList *);
 void resolveIvalSym (initList *, sym_link *);
 value *valFromType (sym_link *);
-value *constFloatVal (char *);
-value *constFixed16x16Val (char *);
+value *constFloatVal (const char *);
+value *constFixed16x16Val (const char *);
 int getNelements (sym_link *, initList *);
 value *valForArray (struct ast *);
 value *valForStructElem (struct ast *, struct ast *);
 value *valForCastAggr (struct ast *, sym_link *, struct ast *, int);
 value *valForCastArr (struct ast * , sym_link *);
 int getNelements (sym_link *, initList *);
 value *valForArray (struct ast *);
 value *valForStructElem (struct ast *, struct ast *);
 value *valForCastAggr (struct ast *, sym_link *, struct ast *, int);
 value *valForCastArr (struct ast * , sym_link *);
-bool convertIListToConstList(initList *src, literalList **lList);
+bool convertIListToConstList(initList *src, literalList **lList, int size);
 literalList *copyLiteralList(literalList *src);
 #endif
 literalList *copyLiteralList(literalList *src);
 #endif