From eae8a3ac3126dc9364bb9625424554bd6c6e4b7c Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Thu, 2 Sep 2010 19:39:31 +0100 Subject: [PATCH] Boolean fixes + autoconfiscation of booleans 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 | 2 +- configure.ac | 2 +- src/ick_bool.h | 27 +++++++++++++++++---------- src/oil.y | 35 +++++++++++------------------------ 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/buildaux/Makefile.am b/buildaux/Makefile.am index fcffec2..d65603b 100644 --- a/buildaux/Makefile.am +++ b/buildaux/Makefile.am @@ -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) diff --git a/configure.ac b/configure.ac index 3859891..c5a9425 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ]]) AC_HEADER_TIME AC_EXEEXT diff --git a/src/ick_bool.h b/src/ick_bool.h index 20f4fbb..aae777d 100644 --- a/src/ick_bool.h +++ b/src/ick_bool.h @@ -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 -#endif -#endif -#ifndef __bool_true_false_are_defined +#ifdef HAVE_STDBOOL_H +# include +#else +# ifndef HAVE__BOOL +# ifdef HAVE_STDINT_H +# include +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@*/ diff --git a/src/oil.y b/src/oil.y index 532ed2e..d7da1d5 100644 --- a/src/oil.y +++ b/src/oil.y @@ -29,20 +29,7 @@ LICENSE TERMS #include #include #include - -/* 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 */ -- 2.43.0