]> thyrsus.com Git - intercal.git/commitdiff
Boolean fixes + autoconfiscation of booleans
authorAlex Smith <ais523@bham.ac.uk>
Thu, 2 Sep 2010 18:39:31 +0000 (19:39 +0100)
committerAlex Smith <ais523@bham.ac.uk>
Thu, 2 Sep 2010 18:39:31 +0000 (19:39 +0100)
Cleaning up ick_bool.h to work even on systems with an insane
stdbool.h; fixing oil.y to use the new booleans throughout;
integrating ick_bool.h into the autoconf system.

buildaux/Makefile.am
configure.ac
src/ick_bool.h
src/oil.y

index fcffec28fd88874b86d4f72250a8e59692ec31d0..d65603b45c511731c233e72d153267b329e07deb 100644 (file)
@@ -146,7 +146,7 @@ dist-hook:
        mv $(distdir)/parser.h $(distdir)/prebuilt
        mv $(distdir)/lexer.c $(distdir)/prebuilt
        mv $(distdir)/oil-oil.c $(distdir)/prebuilt
-       @find $(distdir)/pit -perm -u+x -type f -and -not -name regresscheck | xargs rm
+       -find $(distdir)/pit -perm -u+x -type f -and -not -name regresscheck | xargs rm
        touch $(distdir)/MANIFEST
        (cd $(distdir); find . | sort > MANIFEST)
 
index 3859891300181351062327a78def3922f64a2ed9..c5a94254eb3520567262382024262873eb4c3d03 100644 (file)
@@ -26,6 +26,7 @@ dnl Checks for libraries.
 
 dnl Checks for header files.
 AC_HEADER_STDC
+AC_HEADER_STDBOOL
 AC_CHECK_HEADERS([sys/time.h unistd.h stdarg.h])
 AC_CHECK_HEADERS([stdint.h],[HAVE_STDINT_H=1])
 AC_SUBST(HAVE_STDINT_H)
@@ -37,7 +38,6 @@ dnl likewise for _Bool.
 AC_C_CONST
 AC_C_VOLATILE
 AC_CHECK_SIZEOF([long long int],[0])
-AC_CHECK_SIZEOF([_Bool],[0])
 AC_CHECK_SIZEOF([sig_atomic_t],[0],[[#include <signal.h>]])
 AC_HEADER_TIME
 AC_EXEEXT
index 20f4fbb542a7daaa9d479d12b90c1c1ef2e302a8..aae777d6a6995f44f84d9df5dd444553bdb28d88 100644 (file)
@@ -1,19 +1,26 @@
 /*
  * Hide difference between compilers with the C99 bool type and those without.
  * The main reason this is desirable is so splint can do more rigorous checking
- * on bools.
+ * on bools. This also allows for compilers that define _Bool but not true or
+ * false, etc.
  */
 
 /*@-redef@ -incondefs*/
-#ifdef __STDC_VERSION__
-#if __STDC_VERSION__ >= 199901L
-#include <stdbool.h>
-#endif
-#endif
-#ifndef __bool_true_false_are_defined
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+# ifndef HAVE__BOOL
+#  ifdef HAVE_STDINT_H
+#   include <stdint.h>
+typedef int_fast8_t bool;
+#  else
 typedef int bool;
-#define true 1
-#define false 0
-#define __bool_true_false_are_defined 1
+#  endif
+# else
+typedef _Bool bool
+# endif
+# define true 1
+# define false 0
+# define __bool_true_false_are_defined 1
 #endif
 /*@=redef =incondefs@*/
index 532ed2e8cea5565402ef5a441a419a87f5f4ffc8..d7da1d5fc8f17bf6eaa23b7c11431d2521e9d7eb 100644 (file)
--- a/src/oil.y
+++ b/src/oil.y
@@ -29,20 +29,7 @@ LICENSE TERMS
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-
-/* Autoconf lets us know if we have _Bool available, usually. On DJGPP there's
-   an occasional bug that I haven't managed to reproduce that leaves
-   SIZEOF_BOOL as the null string, so detect that ick_first. */
-#if 100 - SIZEOF__BOOL - 1 == 101
-/* The bug happened, so play safe. */
-  typedef int mybool;
-#else
-# if SIZEOF__BOOL > 0
-  typedef _Bool mybool;
-# else
-  typedef int mybool;
-# endif
-#endif
+#include "ick_bool.h"
 
 /* Define strdup if it isn't available */
 #ifndef HAVE_STRDUP
@@ -76,14 +63,14 @@ struct ickstype
                         there isn't a condition other than maybe mustbemesh */
   const char* nodetypename; /* The name of the type of node this condition matches,
                         or NULL for a LEXERLEAF */
-  mybool usec;        /* Whether to append the value of c to the condition */
-  mybool mustbemesh;  /* Must this node be a mesh or mesh32? */
-  mybool cxneeded;    /* True means calculate c and x for the node and the
+  bool usec;        /* Whether to append the value of c to the condition */
+  bool mustbemesh;  /* Must this node be a mesh or mesh32? */
+  bool cxneeded;    /* True means calculate c and x for the node and the
                         condition is on those; false means append 'condition'
                         to the node itself to form the condition and c and x
                         aren't needed */
-  mybool width32;     /* Generate a 32-bit node? */
-  mybool ublo;        /* Is this a UBLO (if set, generate conditions
+  bool width32;     /* Generate a 32-bit node? */
+  bool ublo;        /* Is this a UBLO (if set, generate conditions
                         to check width)? */
   unsigned long c;    /* The value to append to the condition */
   int replnum;        /* Number of this group for replacements */
@@ -102,10 +89,10 @@ typedef struct ickstype *YYSTYPE;
 void splitend(void);
 void splitstart(void);
 
-void treedepthup(YYSTYPE, mybool);
+void treedepthup(YYSTYPE, bool);
 void treefree(YYSTYPE);
 void gennodepath(unsigned, unsigned long);
-mybool treeshapecond(YYSTYPE, mybool);
+bool treeshapecond(YYSTYPE, bool);
 YYSTYPE treenscheck(YYSTYPE, YYSTYPE, int);
 void treecxcond(YYSTYPE);
 void treerepcount(YYSTYPE, int*);
@@ -162,7 +149,7 @@ int yyerror(char const *);
 #define SPLITMAX 20
 int splitcount=SPLITMAX;
 int filenumber=0;
-mybool inloop=0;
+bool inloop=0;
 %}
 
 /* Various conditions can come out from the lexer. The most common is a char,
@@ -493,7 +480,7 @@ int yylex(void)
   }
 }
 
-void treedepthup(YYSTYPE v, mybool i)
+void treedepthup(YYSTYPE v, bool i)
 {
   if(!v) return;
   treedepthup(v->n1,i);
@@ -521,7 +508,7 @@ void gennodepath(unsigned depth, unsigned long path)
   }
 }
 
-mybool treeshapecond(YYSTYPE v, mybool firstopt)
+bool treeshapecond(YYSTYPE v, bool firstopt)
 {
   if(!v) return firstopt;
   /* To prevent possibly dereferencing a null pointer, check the root ick_first */