Skip to content

Commit c167bb8

Browse files
authored
adds the C99 _Bool type (#39)
Note, this type is different from any integer types as, in ``` _Bool a=1, b=2; assert(a == b); ``` the assertion holds.
1 parent 90d22c0 commit c167bb8

File tree

6 files changed

+6
-1
lines changed

6 files changed

+6
-1
lines changed

frontc/cabs.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and storage =
3636
and base_type =
3737
| NO_TYPE (** Old K&R declaration without type *)
3838
| VOID (** "void" type *)
39+
| BOOL (** C99 boolean (_Bool) type *)
3940
| CHAR of sign (** "char" type with sign modifier *)
4041
| INT of size * sign (** "int" type with size and sign modifiers *)
4142
| BITFIELD of sign * expression

frontc/clexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ let keywords =
153153
("__restrict", id RESTRICT);
154154
("restrict", id RESTRICT);
155155
("char", id CHAR);
156+
("_Bool", id BOOL);
156157
("int", id INT);
157158
("float", id FLOAT);
158159
("double", id DOUBLE);

frontc/cparser.mly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ only_dec:
731731
/*** Base type ***/
732732
qual_type:
733733
| VOID {(VOID, [])}
734+
| BOOL {(BOOL, [])}
734735
| CHAR {(CHAR NO_SIGN, [])}
735736
| INT {(INT (NO_SIZE, NO_SIGN), [])}
736737
| FLOAT {(FLOAT false, [])}

frontc/cprint.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ let rec print_base_type typ =
158158
match typ with
159159
NO_TYPE -> ()
160160
| VOID -> print "void"
161+
| BOOL -> print "_Bool"
161162
| CHAR sign -> print ((get_sign sign) ^ "char")
162163
| INT (size, sign) -> print ((get_sign sign) ^ (get_size size) ^ "int")
163164
| BITFIELD (sign, _) -> print ((get_sign sign) ^ "int")

frontc/ctokens.mly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
%token <Cabs.gnu_attrs> GNU_ATTRS
88

99
%token EOF
10-
%token CHAR INT DOUBLE FLOAT VOID
10+
%token CHAR BOOL INT DOUBLE FLOAT VOID
1111
%token ENUM STRUCT TYPEDEF UNION
1212
%token SIGNED UNSIGNED LONG SHORT COMPLEX
1313
%token VOLATILE EXTERN STATIC CONST AUTO REGISTER RESTRICT

frontc/ctoxml.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ and convert_type _type =
235235
let base_type name = Cxml.new_elt name [] [] in
236236
match _type with
237237
NO_TYPE -> convert_type (INT (NO_SIZE, NO_SIGN))
238+
| BOOL -> base_type "bool"
238239
| VOID -> base_type "void"
239240
| CHAR NO_SIGN
240241
| CHAR SIGNED -> base_type "char"

0 commit comments

Comments
 (0)