Skip to content

Commit 5f6ada2

Browse files
committed
support _Bool.
1 parent 513de80 commit 5f6ada2

23 files changed

+779
-69
lines changed

README.Win32

+4
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ is libcstl unit testing execute file. You will need cmockery.lib
2323
and google\*.h, the header files of cmockery libaray, in vc8/vc9
2424
directory.
2525

26+
NOTE
27+
-----------------------------------------
28+
LIBCSTL WILL BE CANCEL MSVS SUPPORT IN FURTER VERSION,
29+
BECAUSE THE MSVS DOES NOT SUPPORT C99 FULLY.

cstl/cstl_def.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ extern "C" {
3939
#include <ctype.h>
4040
#include <float.h>
4141
#include <time.h>
42+
#ifndef _MSC_VER
43+
# include <stdbool.h>
44+
#endif
4245

4346
/** constant declaration and macro section **/
4447
#ifdef _CSTL_UNIT_TESTING
@@ -73,13 +76,13 @@ extern "C" {
7376
#define CSTL_MINOR_VERSION 3
7477
#define CSTL_REVISION_VERSION 0
7578

79+
#ifdef _MSC_VER
7680
/**
7781
* for bool_t type
7882
*/
79-
#define FALSE 0 /* declaration false bool type */
8083
#define false 0
81-
#define TRUE 1 /* declaration true bool type */
8284
#define true 1
85+
#endif
8386

8487
/** data type declaration and struct, union, enum section **/
8588
typedef unsigned char _byte_t;

cstl/cstl_function.h

+9
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ extern void fun_less_equal_hash_multimap(const void* cpv_first, const void* cpv_
388388
* @remarks The input and output must not be NULL, otherwise the behavior is undefined.
389389
*/
390390
extern void fun_logical_and_cstl_bool(const void* cpv_first, const void* cpv_second, void* pv_output);
391+
#ifndef _MSC_VER
392+
extern void fun_logical_and_bool(const void* cpv_first, const void* cpv_second, void* pv_output);
393+
#endif
391394

392395
/**
393396
* Logical or.
@@ -398,6 +401,9 @@ extern void fun_logical_and_cstl_bool(const void* cpv_first, const void* cpv_sec
398401
* @remarks The input and output must not be NULL, otherwise the behavior is undefined.
399402
*/
400403
extern void fun_logical_or_cstl_bool(const void* cpv_first, const void* cpv_second, void* pv_output);
404+
#ifndef _MSC_VER
405+
extern void fun_logical_or_bool(const void* cpv_first, const void* cpv_second, void* pv_output);
406+
#endif
401407

402408
/**
403409
* Logical not.
@@ -407,6 +413,9 @@ extern void fun_logical_or_cstl_bool(const void* cpv_first, const void* cpv_seco
407413
* @remarks The input and output must not be NULL, otherwise the behavior is undefined.
408414
*/
409415
extern void fun_logical_not_cstl_bool(const void* cpv_input, void* pv_output);
416+
#ifndef _MSC_VER
417+
extern void fun_logical_not_bool(const void* cpv_input, void* pv_output);
418+
#endif
410419

411420
/**
412421
* Random number.

cstl/cstl_types.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extern "C" {
6868
#define _POINTER_TYPE "void*"
6969

7070
#define _CSTL_BOOL_TYPE "bool_t"
71+
#define _BOOL_TYPE "_Bool"
7172
/* cstl type */
7273
#define _VECTOR_TYPE "vector_t"
7374
#define _LIST_TYPE "list_t"

doc/project/libcstl.bnf

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ space : ' ' | '\t' | '\v' | '\f' | '\r' | '\n'
2929

3030
keyword:
3131
void
32-
char, int, short, long, float, double, signed, unsigned, bool_t,
32+
char, int, short, long, float, double, signed, unsigned, bool_t, _Bool
3333
struct, enum, union,
3434
vector_t, list_t, slist_t, deque_t, stack_t, queue_t, priority_queue_t,
3535
set_t, map_t, multiset_t, multimap_t,
@@ -65,7 +65,7 @@ C_BUILTIN -> char | signed char |
6565
long double |
6666
char* |
6767
void* |
68-
bool_t
68+
bool_t | _Bool
6969
USER_DEFINE -> USER_DEFINE_TYPE identifier | identifier
7070
USER_DEFINE_TYPE -> struct | enum | union
7171
CSTL_BUILTIN -> SEQUENCE | RELATION | string_t | ITERATOR
@@ -81,7 +81,7 @@ RELATION -> RELATION_NAME < TYPE_DESCRIPT , TYPE_DESCRIPT >
8181
RELATION_NAME -> map_t | multimap_t | hash_map_t | hash_multimap_t | pair_t
8282
========================================================================
8383
C_BUILTIN -> SIMPLE_BUILTIN | SIGNED_BUILTIN | UNSIGNED_BUILTIN | POINTER_BUILTIN
84-
SIMPLE_BUILTIN -> char | short | short int | int | long | long int | bool_t
84+
SIMPLE_BUILTIN -> char | short | short int | int | long | long int | bool_t | _Bool
8585
float | double | long double
8686
SIGNED_BUILTIN -> signed char |
8787
signed short | signed short int |
@@ -97,7 +97,7 @@ POINTER_BUILTIN -> char * | void *
9797
TYPE_DESCRIPT -> C_BUILTIN | USER_DEFINE | CSTL_BUILTIN
9898

9999
C_BUILTIN -> SIMPLE_BUILTIN | SIGNED_BUILTIN | UNSIGNED_BUILTIN | POINTER_BUILTIN
100-
SIMPLE_BUILTIN -> char POINTER_SUFFIX | short COMMON_SUFFIX | int | long SIMPLE_LONG_SUFFIX | float | double | bool_t
100+
SIMPLE_BUILTIN -> char POINTER_SUFFIX | short COMMON_SUFFIX | int | long SIMPLE_LONG_SUFFIX | float | double | bool_t | _Bool
101101
SIGNED_BUILTIN -> signed COMPLEX_SUFFIX
102102
UNSIGNED_BUILTIN -> unsigned COMPLEX_SUFFIX
103103
POINTER_BUILTIN -> void *
@@ -121,7 +121,7 @@ SEQUENCE_NAME -> vector_t | list_t | slist_t | deque_t | queue_t | stack_t | pri
121121
RELATION -> RELATION_NAME < TYPE_DESCRIPT , TYPE_DESCRIPT >
122122
RELATION_NAME -> map_t | multimap_t | hash_map_t | hash_multimap_t | pair_t
123123
---------------------------------------------------------------------------
124-
first(TYPE_DESCRIPT) = {char, short, int, long, float, double, signed, unsigned, void, bool_t,
124+
first(TYPE_DESCRIPT) = {char, short, int, long, float, double, signed, unsigned, void, bool_t, _Bool,
125125
struct, enum, union, identifier,
126126
vector_t, list_t, slist_t, deque_t, queue_t, stack_t, priority_queue_t,
127127
set_t, map_t, multiset_t, multimap_t, hash_set_t, hash_map_t, hash_multiset_t,
@@ -132,8 +132,8 @@ first(TYPE_DESCRIPT) = {char, short, int, long, float, double, signed, unsigned,
132132
string_iterator_t,
133133
input_iterator_t, output_iterator_t, forward_iterator_t, bidirectional_iterator_t,
134134
random_access_iterator_t}
135-
first(C_BUILTIN) = {char, short, int, long, float, double, signed, unsigned, void, bool_t}
136-
first(SIMPLE_BUILTIN) = {char, short, int, long, float, double, bool_t}
135+
first(C_BUILTIN) = {char, short, int, long, float, double, signed, unsigned, void, bool_t, _Bool}
136+
first(SIMPLE_BUILTIN) = {char, short, int, long, float, double, bool_t, _Bool}
137137
first(SIGNED_BUILTIN) = {signed}
138138
first(UNSIGNED_BUILTIN) = {unsigned}
139139
first(POINTER_BUILTIN) = {void}
@@ -203,7 +203,7 @@ select(TYPE_DESCRIPT -> CSTL_BUILTIN) = {vector_t, list_t, slist_t, deque_t, que
203203
input_iterator_t, output_iterator_t, forward_iterator_t, bidirectional_iterator_t,
204204
random_access_iterator_t}
205205

206-
select(C_BUILTIN -> SIMPLE_BUILTIN) = {char, short, int, long, float, double, bool_t}
206+
select(C_BUILTIN -> SIMPLE_BUILTIN) = {char, short, int, long, float, double, bool_t, _Bool}
207207
select(C_BUILTIN -> SIGNED_BUILTIN) = {signed}
208208
select(C_BUILTIN -> UNSIGNED_BUILTIN) = {unsigned}
209209
select(C_BUILTIN -> POINTER_BUILTIN) = {void}
@@ -215,6 +215,7 @@ select(SIMPLE_BUILTIN -> long SIMPLE_LONG_SUFFIX) = {long}
215215
select(SIMPLE_BUILTIN -> float) = {float}
216216
select(SIMPLE_BUILTIN -> double) = {double}
217217
select(SIMPLE_BUILTIN -> bool_t) = {bool_t}
218+
select(SIMPLE_BUILTIN -> _Bool) = {_Bool}
218219

219220
selcet(SIGNED_BUILTIN -> signed COMPLEX_SUFFIX) = {signed}
220221
select(UNSIGNED_BUILTIN -> unsigned COMPLEX_SUFFIX) = {unsigned}

src/cstl_function.c

+27
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,15 @@ void fun_logical_and_cstl_bool(const void* cpv_first, const void* cpv_second, vo
18371837
*(bool_t*)pv_output = *(bool_t*)cpv_first && *(bool_t*)cpv_second;
18381838
}
18391839

1840+
#ifndef _MSC_VER
1841+
void fun_logical_and_bool(const void* cpv_first, const void* cpv_second, void* pv_output)
1842+
{
1843+
assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL);
1844+
1845+
*(bool_t*)pv_output = *(_Bool*)cpv_first && *(_Bool*)cpv_second;
1846+
}
1847+
#endif
1848+
18401849
/**
18411850
* Logical or.
18421851
*/
@@ -1847,6 +1856,15 @@ void fun_logical_or_cstl_bool(const void* cpv_first, const void* cpv_second, voi
18471856
*(bool_t*)pv_output = *(bool_t*)cpv_first || *(bool_t*)cpv_second;
18481857
}
18491858

1859+
#ifndef _MSC_VER
1860+
void fun_logical_or_bool(const void* cpv_first, const void* cpv_second, void* pv_output)
1861+
{
1862+
assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL);
1863+
1864+
*(bool_t*)pv_output = *(_Bool*)cpv_first || *(_Bool*)cpv_second;
1865+
}
1866+
#endif
1867+
18501868
/**
18511869
* Logical not.
18521870
*/
@@ -1857,6 +1875,15 @@ void fun_logical_not_cstl_bool(const void* cpv_input, void* pv_output)
18571875
*(bool_t*)pv_output = !*(bool_t*)cpv_input;
18581876
}
18591877

1878+
#ifndef _MSC_VER
1879+
void fun_logical_not_bool(const void* cpv_input, void* pv_output)
1880+
{
1881+
assert(cpv_input != NULL && pv_output != NULL);
1882+
1883+
*(bool_t*)pv_output = !*(_Bool*)cpv_input;
1884+
}
1885+
#endif
1886+
18601887
/**
18611888
* Random number.
18621889
*/

src/cstl_function_private.c

+14
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ ufun_t _fun_get_unary(iterator_t it_iter, fun_type_t ftype_type)
137137
if (ftype_type == _LOGICAL_NOT_FUN) {
138138
return fun_logical_not_cstl_bool;
139139
}
140+
#ifndef _MSC_VER
141+
} else if (strncmp(s_typename, _BOOL_TYPE, _TYPE_NAME_SIZE) == 0) { /* _Bool */
142+
if (ftype_type == _LOGICAL_NOT_FUN) {
143+
return fun_logical_not_bool;
144+
}
145+
#endif
140146
}
141147

142148
return fun_default_unary;
@@ -359,6 +365,14 @@ bfun_t _fun_get_binary(iterator_t it_iter, fun_type_t ftype_type)
359365
case _LOGICAL_OR_FUN: return fun_logical_or_cstl_bool; break;
360366
default: break;
361367
}
368+
#ifndef _MSC_VER
369+
} else if (strncmp(s_typename, _BOOL_TYPE, _TYPE_NAME_SIZE) == 0) { /* _Bool */
370+
switch (ftype_type) {
371+
case _LOGICAL_AND_FUN: return fun_logical_and_bool; break;
372+
case _LOGICAL_OR_FUN: return fun_logical_or_bool; break;
373+
default: break;
374+
}
375+
#endif
362376
} else if (strncmp(s_typename, _VECTOR_TYPE, _TYPE_NAME_SIZE) == 0) { /* vector_t */
363377
switch (ftype_type) {
364378
case _EQUAL_FUN: return fun_equal_vector; break;

src/cstl_types.c

+6
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ void _type_get_varg_value(_typeinfo_t* pt_typeinfo, va_list val_elemlist, void*
552552
assert(b_result);
553553
memset(pv_output, 0x00, pt_typeinfo->_pt_type->_t_typesize);
554554
}
555+
#ifndef _MSC_VER
556+
} else if (strncmp(pt_typeinfo->_pt_type->_s_typename, _BOOL_TYPE, _TYPE_NAME_SIZE) == 0) {
557+
/* _Bool */
558+
assert(pt_typeinfo->_pt_type->_t_typesize == sizeof(_Bool));
559+
*(_Bool*)pv_output = va_arg(val_elemlist, int);
560+
#endif
555561
} else {
556562
/* invalid c builtin style */
557563
assert(false);

src/cstl_types_aux.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* The implementation of cstl types auxiliary functions.
3-
* Copyright (C) 2008 - 2012 Wangbo
3+
* Copyright (C) 2008 - 2014 Wangbo
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -248,6 +248,12 @@ void _type_register_c_builtin(void)
248248
_TYPE_REGISTER_TYPE(void*, _POINTER_TYPE, pointer, _TYPE_C_BUILTIN);
249249
_TYPE_REGISTER_TYPE_NODE(void*, _POINTER_TYPE);
250250

251+
#ifndef _MSC_VER
252+
/* register _Bool */
253+
_TYPE_REGISTER_TYPE(_Bool, _BOOL_TYPE, bool, _TYPE_C_BUILTIN);
254+
_TYPE_REGISTER_TYPE_NODE(_Bool, _BOOL_TYPE);
255+
#endif
256+
251257
_TYPE_REGISTER_END();
252258
}
253259

src/cstl_types_builtin.c

+28
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,34 @@ void _type_destroy_iterator(const void* cpv_input, void* pv_output)
999999
_type_destroy_default(cpv_input, pv_output);
10001000
}
10011001

1002+
#ifndef _MSC_VER
1003+
/* _Bool */
1004+
void _type_init_bool(const void* cpv_input, void* pv_output)
1005+
{
1006+
assert(cpv_input != NULL && pv_output != NULL);
1007+
*(_Bool*)cpv_input = false;
1008+
*(bool_t*)pv_output = true;
1009+
}
1010+
1011+
void _type_copy_bool(const void* cpv_first, const void* cpv_second, void* pv_output)
1012+
{
1013+
assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL);
1014+
*(_Bool*)cpv_first = *(_Bool*)cpv_second;
1015+
*(bool_t*)pv_output = true;
1016+
}
1017+
1018+
void _type_less_bool(const void* cpv_first, const void* cpv_second, void* pv_output)
1019+
{
1020+
assert(cpv_first != NULL && cpv_second != NULL && pv_output != NULL);
1021+
*(bool_t*)pv_output = *(_Bool*)cpv_first < *(_Bool*)cpv_second ? true : false;
1022+
}
1023+
1024+
void _type_destroy_bool(const void* cpv_input, void* pv_output)
1025+
{
1026+
_type_destroy_default(cpv_input, pv_output);
1027+
}
1028+
#endif
1029+
10021030
/** local function implementation section **/
10031031

10041032
/** eof **/

src/cstl_types_builtin.h

+8
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ extern void _type_copy_iterator(const void* cpv_first, const void* cpv_second, v
208208
extern void _type_less_iterator(const void* cpv_first, const void* cpv_second, void* pv_output);
209209
extern void _type_destroy_iterator(const void* cpv_input, void* pv_output);
210210

211+
#ifndef _MSC_VER
212+
/* _Bool */
213+
extern void _type_init_bool(const void* cpv_input, void* pv_output);
214+
extern void _type_copy_bool(const void* cpv_first, const void* cpv_second, void* pv_output);
215+
extern void _type_less_bool(const void* cpv_first, const void* cpv_second, void* pv_output);
216+
extern void _type_destroy_bool(const void* cpv_input, void* pv_output);
217+
#endif
218+
211219
#ifdef __cplusplus
212220
}
213221
#endif

src/cstl_types_parse.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define _TOKEN_TEXT_UNSIGNED "unsigned"
5151
#define _TOKEN_TEXT_VOID "void"
5252
#define _TOKEN_TEXT_CSTL_BOOL "bool_t"
53+
#define _TOKEN_TEXT_BOOL "_Bool"
5354
#define _TOKEN_TEXT_STRUCT "struct"
5455
#define _TOKEN_TEXT_ENUM "enum"
5556
#define _TOKEN_TEXT_UNION "union"
@@ -127,6 +128,7 @@ static keytable_t _sgt_table[] = {
127128
{_TOKEN_KEY_UNSIGNED, _TOKEN_TEXT_UNSIGNED},
128129
{_TOKEN_KEY_VOID, _TOKEN_TEXT_VOID},
129130
{_TOKEN_KEY_CSTL_BOOL, _TOKEN_TEXT_CSTL_BOOL},
131+
{_TOKEN_KEY_BOOL, _TOKEN_TEXT_BOOL},
130132
{_TOKEN_KEY_STRUCT, _TOKEN_TEXT_STRUCT},
131133
{_TOKEN_KEY_ENUM, _TOKEN_TEXT_ENUM},
132134
{_TOKEN_KEY_UNION, _TOKEN_TEXT_UNION},
@@ -214,6 +216,7 @@ _typestyle_t _type_get_style(const char* s_typename, char* s_formalname)
214216
case _TOKEN_KEY_UNSIGNED:
215217
case _TOKEN_KEY_VOID:
216218
case _TOKEN_KEY_CSTL_BOOL:
219+
case _TOKEN_KEY_BOOL:
217220
t_style = _type_parse_c_builtin(s_formalname) ? _TYPE_C_BUILTIN : _TYPE_INVALID;
218221
break;
219222
/* TYPE_DESCRIPT -> USER_DEFINE */
@@ -397,6 +400,7 @@ bool_t _type_parse_c_builtin(char* s_formalname)
397400
case _TOKEN_KEY_FLOAT:
398401
case _TOKEN_KEY_DOUBLE:
399402
case _TOKEN_KEY_CSTL_BOOL:
403+
case _TOKEN_KEY_BOOL:
400404
return _type_parse_simple_builtin(s_formalname);
401405
break;
402406
/* C_BUILTIN -> SIGNED_BUILTIN */
@@ -510,7 +514,7 @@ bool_t _type_parse_simple_builtin(char* s_formalname)
510514
assert(s_formalname != NULL);
511515
/*
512516
* SIMPLE_BUILTIN -> char POINTER_SUFFIX | short COMMON_SUFFIX | int |
513-
* long SIMPLE_LONG_SUFFIX | float | double | bool_t
517+
* long SIMPLE_LONG_SUFFIX | float | double | bool_t | _Bool
514518
*/
515519
switch (_gt_typeanalysis._t_token) {
516520
/* SIMPLE_BUILTIN -> char POINTER_SUFFIX */
@@ -551,6 +555,11 @@ bool_t _type_parse_simple_builtin(char* s_formalname)
551555
_TOKEN_MATCH(_TOKEN_TEXT_CSTL_BOOL, s_formalname);
552556
return true;
553557
break;
558+
/* SIMPLE_BUILTIN -> _Bool */
559+
case _TOKEN_KEY_BOOL:
560+
_TOKEN_MATCH(_TOKEN_TEXT_BOOL, s_formalname);
561+
return true;
562+
break;
554563
default:
555564
return false;
556565
break;
@@ -1025,6 +1034,7 @@ bool_t _type_parse_type_descript(char* s_formalname)
10251034
case _TOKEN_KEY_UNSIGNED:
10261035
case _TOKEN_KEY_VOID:
10271036
case _TOKEN_KEY_CSTL_BOOL:
1037+
case _TOKEN_KEY_BOOL:
10281038
return _type_parse_c_builtin(s_formalname);
10291039
break;
10301040
/* TYPE_DESCRIPT -> USER_DEFINE */

src/cstl_types_parse.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef enum _tagtypetoken
4646
/* c builtin */
4747
_TOKEN_KEY_CHAR, _TOKEN_KEY_SHORT, _TOKEN_KEY_INT, _TOKEN_KEY_LONG, _TOKEN_KEY_FLOAT,
4848
_TOKEN_KEY_DOUBLE, _TOKEN_KEY_SIGNED, _TOKEN_KEY_UNSIGNED, _TOKEN_KEY_VOID,
49-
_TOKEN_KEY_CSTL_BOOL,
49+
_TOKEN_KEY_CSTL_BOOL, _TOKEN_KEY_BOOL,
5050
/* user define */
5151
_TOKEN_KEY_STRUCT, _TOKEN_KEY_ENUM, _TOKEN_KEY_UNION, _TOKEN_IDENTIFIER,
5252
/* cstl container */

0 commit comments

Comments
 (0)