Skip to content

Commit

Permalink
scanner: Skeleton no longer includes integer limit macros.
Browse files Browse the repository at this point in the history
The [U]INT{8,16,32}_{MIN,MAX} macros are never used in skeleton code.
Having them in skeleton just increases the chance of conflicts in case
that user defines them in non-C99 environment (see issue #307, when
flex code is built in Visual C++ (before VS2013)).

flexint.h is now split in two files. Only "flexint_shared.h" will be
included in skeleton now, which defines flex integral types.
flexint.h contains integer limits macros that would be used in flex
only.

Signed-off-by: Kang-Che Sung <[email protected]>
  • Loading branch information
Explorer09 authored and westes committed Mar 8, 2018
1 parent ec4f23d commit 5574881
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ COMMON_SOURCES = \
filter.c \
flexdef.h \
flexint.h \
flexint_shared.h \
gen.c \
main.c \
misc.c \
Expand Down Expand Up @@ -95,7 +96,7 @@ CLEANFILES = stage1scan.c stage1flex$(EXEEXT)

MAINTAINERCLEANFILES = skel.c

skel.c: flex.skl mkskel.sh flexint.h tables_shared.h tables_shared.c
skel.c: flex.skl mkskel.sh flexint_shared.h tables_shared.h tables_shared.c
$(SHELL) $(srcdir)/mkskel.sh $(srcdir) $(m4) $(VERSION) > $@.tmp
mv $@.tmp $@

Expand Down
8 changes: 4 additions & 4 deletions src/flex.skl
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,6 @@ m4_ifdef( [[M4_YY_ALWAYS_INTERACTIVE]], ,
%endif
/* end standard C headers. */

%if-c-or-c++
m4preproc_include(`flexint.h')
%endif

/* begin standard C++ headers. */
%if-c++-only
#include <iostream>
Expand All @@ -262,6 +258,10 @@ m4preproc_include(`flexint.h')
/* end standard C++ headers. */
%endif

%if-c-or-c++
m4preproc_include(`flexint_shared.h')
%endif

/* TODO: this is always defined, so inline it */
#define yyconst const

Expand Down
24 changes: 4 additions & 20 deletions src/flexint.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,17 @@
#ifndef FLEXINT_H
#define FLEXINT_H

/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */

#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L

/* C++ systems might need __STDC_LIMIT_MACROS defined before including
* <stdint.h>, if you want the limit (max/min) macros for int types.
*/
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS 1
#endif

#include <inttypes.h>
typedef int8_t flex_int8_t;
typedef uint8_t flex_uint8_t;
typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
typedef int flex_int32_t;
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
/* "flexint_shared.h" will be included also in skeleton. It will include
* <inttypes.h> (if available) and define flex's integral types.
*/
#include "flexint_shared.h"

/* Limits of integral types. */
#ifndef INT8_MIN
Expand Down Expand Up @@ -65,6 +51,4 @@ typedef unsigned int flex_uint32_t;
#define SIZE_MAX (~(size_t)0)
#endif

#endif /* ! C99 */

#endif /* ! FLEXINT_H */
22 changes: 22 additions & 0 deletions src/flexint_shared.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* flex integer type definitions */

/* Prefer C99 integer types if available. */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/* Include <inttypes.h> and not <stdint.h> because Solaris 2.6 has the former
* and not the latter.
*/
#include <inttypes.h>
typedef int8_t flex_int8_t;
typedef uint8_t flex_uint8_t;
typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
typedef int flex_int32_t;
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
#endif /* ! C99 */

0 comments on commit 5574881

Please sign in to comment.