Skip to content

Commit ab03aa8

Browse files
authored
Improve clang-format friendliness of HANDLE_OPTION macro (#1066)
1 parent a35d672 commit ab03aa8

File tree

1 file changed

+63
-62
lines changed

1 file changed

+63
-62
lines changed

src/libbson/src/bson/bson-json.c

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ _noop (void)
370370
read_state_names[bson->read_state]); \
371371
return; \
372372
}
373-
#define HANDLE_OPTION(_key, _type, _state) \
374-
(len == strlen (_key) && strncmp ((const char *) val, (_key), len) == 0) \
373+
#define HANDLE_OPTION(_selection_statement, _key, _type, _state) \
374+
_selection_statement (len == strlen (_key) && \
375+
strncmp ((const char *) val, (_key), len) == 0) \
375376
{ \
376377
if (bson->bson_type && bson->bson_type != (_type)) { \
377378
_bson_json_read_set_error (reader, \
@@ -1368,98 +1369,98 @@ _bson_json_read_map_key (bson_json_reader_t *reader, /* IN */
13681369
_bson_json_save_map_key (bson, val, len);
13691370
}
13701371

1371-
/* clang-format off */
13721372
if (bson->read_state == BSON_JSON_IN_BSON_TYPE) {
1373-
if
1374-
HANDLE_OPTION ("$regex", BSON_TYPE_REGEX, BSON_JSON_LF_REGEX)
1375-
else if
1376-
HANDLE_OPTION ("$options", BSON_TYPE_REGEX, BSON_JSON_LF_OPTIONS)
1377-
else if
1378-
HANDLE_OPTION ("$oid", BSON_TYPE_OID, BSON_JSON_LF_OID)
1379-
else if
1380-
HANDLE_OPTION ("$binary", BSON_TYPE_BINARY, BSON_JSON_LF_BINARY)
1381-
else if
1382-
HANDLE_OPTION ("$type", BSON_TYPE_BINARY, BSON_JSON_LF_TYPE)
1383-
else if
1384-
HANDLE_OPTION ("$uuid", BSON_TYPE_BINARY, BSON_JSON_LF_UUID)
1385-
else if
1386-
HANDLE_OPTION ("$date", BSON_TYPE_DATE_TIME, BSON_JSON_LF_DATE)
1387-
else if
1388-
HANDLE_OPTION (
1389-
"$undefined", BSON_TYPE_UNDEFINED, BSON_JSON_LF_UNDEFINED)
1390-
else if
1391-
HANDLE_OPTION ("$minKey", BSON_TYPE_MINKEY, BSON_JSON_LF_MINKEY)
1392-
else if
1393-
HANDLE_OPTION ("$maxKey", BSON_TYPE_MAXKEY, BSON_JSON_LF_MAXKEY)
1394-
else if
1395-
HANDLE_OPTION ("$numberInt", BSON_TYPE_INT32, BSON_JSON_LF_INT32)
1396-
else if
1397-
HANDLE_OPTION ("$numberLong", BSON_TYPE_INT64, BSON_JSON_LF_INT64)
1398-
else if
1399-
HANDLE_OPTION ("$numberDouble", BSON_TYPE_DOUBLE, BSON_JSON_LF_DOUBLE)
1400-
else if
1401-
HANDLE_OPTION ("$symbol", BSON_TYPE_SYMBOL, BSON_JSON_LF_SYMBOL)
1402-
else if
1403-
HANDLE_OPTION (
1404-
"$numberDecimal", BSON_TYPE_DECIMAL128, BSON_JSON_LF_DECIMAL128)
1405-
else if (!strcmp ("$timestamp", (const char *) val)) {
1373+
HANDLE_OPTION (if, "$regex", BSON_TYPE_REGEX, BSON_JSON_LF_REGEX)
1374+
HANDLE_OPTION (else if, "$options", BSON_TYPE_REGEX, BSON_JSON_LF_OPTIONS)
1375+
HANDLE_OPTION (else if, "$oid", BSON_TYPE_OID, BSON_JSON_LF_OID)
1376+
HANDLE_OPTION (else if, "$binary", BSON_TYPE_BINARY, BSON_JSON_LF_BINARY)
1377+
HANDLE_OPTION (else if, "$type", BSON_TYPE_BINARY, BSON_JSON_LF_TYPE)
1378+
HANDLE_OPTION (else if, "$uuid", BSON_TYPE_BINARY, BSON_JSON_LF_UUID)
1379+
HANDLE_OPTION (else if, "$date", BSON_TYPE_DATE_TIME, BSON_JSON_LF_DATE)
1380+
HANDLE_OPTION (
1381+
else if, "$undefined", BSON_TYPE_UNDEFINED, BSON_JSON_LF_UNDEFINED)
1382+
HANDLE_OPTION (else if, "$minKey", BSON_TYPE_MINKEY, BSON_JSON_LF_MINKEY)
1383+
HANDLE_OPTION (else if, "$maxKey", BSON_TYPE_MAXKEY, BSON_JSON_LF_MAXKEY)
1384+
HANDLE_OPTION (else if, "$numberInt", BSON_TYPE_INT32, BSON_JSON_LF_INT32)
1385+
HANDLE_OPTION (
1386+
else if, "$numberLong", BSON_TYPE_INT64, BSON_JSON_LF_INT64)
1387+
HANDLE_OPTION (
1388+
else if, "$numberDouble", BSON_TYPE_DOUBLE, BSON_JSON_LF_DOUBLE)
1389+
HANDLE_OPTION (else if, "$symbol", BSON_TYPE_SYMBOL, BSON_JSON_LF_SYMBOL)
1390+
HANDLE_OPTION (else if,
1391+
"$numberDecimal",
1392+
BSON_TYPE_DECIMAL128,
1393+
BSON_JSON_LF_DECIMAL128)
1394+
else if (!strcmp ("$timestamp", (const char *) val))
1395+
{
14061396
bson->bson_type = BSON_TYPE_TIMESTAMP;
14071397
bson->read_state = BSON_JSON_IN_BSON_TYPE_TIMESTAMP_STARTMAP;
1408-
} else if (!strcmp ("$regularExpression", (const char *) val)) {
1398+
}
1399+
else if (!strcmp ("$regularExpression", (const char *) val))
1400+
{
14091401
bson->bson_type = BSON_TYPE_REGEX;
14101402
bson->read_state = BSON_JSON_IN_BSON_TYPE_REGEX_STARTMAP;
1411-
} else if (!strcmp ("$dbPointer", (const char *) val)) {
1403+
}
1404+
else if (!strcmp ("$dbPointer", (const char *) val))
1405+
{
14121406
/* start parsing "key": {"$dbPointer": {...}}, save "key" for later */
14131407
_bson_json_buf_set (
14141408
&bson->dbpointer_key, bson->key_buf.buf, bson->key_buf.len);
14151409

14161410
bson->bson_type = BSON_TYPE_DBPOINTER;
14171411
bson->read_state = BSON_JSON_IN_BSON_TYPE_DBPOINTER_STARTMAP;
1418-
} else if (!strcmp ("$code", (const char *) val)) {
1412+
}
1413+
else if (!strcmp ("$code", (const char *) val))
1414+
{
14191415
_bson_json_read_code_or_scope_key (
14201416
bson, false /* is_scope */, val, len);
1421-
} else if (!strcmp ("$scope", (const char *) val)) {
1417+
}
1418+
else if (!strcmp ("$scope", (const char *) val))
1419+
{
14221420
_bson_json_read_code_or_scope_key (
14231421
bson, true /* is_scope */, val, len);
1424-
} else {
1422+
}
1423+
else
1424+
{
14251425
_bson_json_bad_key_in_type (reader, val);
14261426
}
14271427
} else if (bson->read_state == BSON_JSON_IN_BSON_TYPE_DATE_NUMBERLONG) {
1428-
if
1429-
HANDLE_OPTION ("$numberLong", BSON_TYPE_DATE_TIME, BSON_JSON_LF_INT64)
1430-
else {
1428+
HANDLE_OPTION (if, "$numberLong", BSON_TYPE_DATE_TIME, BSON_JSON_LF_INT64)
1429+
else
1430+
{
14311431
_bson_json_bad_key_in_type (reader, val);
14321432
}
14331433
} else if (bson->read_state == BSON_JSON_IN_BSON_TYPE_TIMESTAMP_VALUES) {
1434-
if
1435-
HANDLE_OPTION ("t", BSON_TYPE_TIMESTAMP, BSON_JSON_LF_TIMESTAMP_T)
1436-
else if
1437-
HANDLE_OPTION ("i", BSON_TYPE_TIMESTAMP, BSON_JSON_LF_TIMESTAMP_I)
1438-
else {
1434+
HANDLE_OPTION (if, "t", BSON_TYPE_TIMESTAMP, BSON_JSON_LF_TIMESTAMP_T)
1435+
HANDLE_OPTION (
1436+
else if, "i", BSON_TYPE_TIMESTAMP, BSON_JSON_LF_TIMESTAMP_I)
1437+
else
1438+
{
14391439
_bson_json_bad_key_in_type (reader, val);
14401440
}
14411441
} else if (bson->read_state == BSON_JSON_IN_BSON_TYPE_REGEX_VALUES) {
1442-
if
1443-
HANDLE_OPTION (
1444-
"pattern", BSON_TYPE_REGEX, BSON_JSON_LF_REGULAR_EXPRESSION_PATTERN)
1445-
else if
1446-
HANDLE_OPTION (
1447-
"options", BSON_TYPE_REGEX, BSON_JSON_LF_REGULAR_EXPRESSION_OPTIONS)
1448-
else {
1442+
HANDLE_OPTION (if,
1443+
"pattern",
1444+
BSON_TYPE_REGEX,
1445+
BSON_JSON_LF_REGULAR_EXPRESSION_PATTERN)
1446+
HANDLE_OPTION (else if,
1447+
"options",
1448+
BSON_TYPE_REGEX,
1449+
BSON_JSON_LF_REGULAR_EXPRESSION_OPTIONS)
1450+
else
1451+
{
14491452
_bson_json_bad_key_in_type (reader, val);
14501453
}
14511454
} else if (bson->read_state == BSON_JSON_IN_BSON_TYPE_BINARY_VALUES) {
1452-
if
1453-
HANDLE_OPTION ("base64", BSON_TYPE_BINARY, BSON_JSON_LF_BINARY)
1454-
else if
1455-
HANDLE_OPTION ("subType", BSON_TYPE_BINARY, BSON_JSON_LF_TYPE)
1456-
else {
1455+
HANDLE_OPTION (if, "base64", BSON_TYPE_BINARY, BSON_JSON_LF_BINARY)
1456+
HANDLE_OPTION (else if, "subType", BSON_TYPE_BINARY, BSON_JSON_LF_TYPE)
1457+
else
1458+
{
14571459
_bson_json_bad_key_in_type (reader, val);
14581460
}
14591461
} else {
14601462
_bson_json_save_map_key (bson, val, len);
14611463
}
1462-
/* clang-format on */
14631464
}
14641465

14651466

0 commit comments

Comments
 (0)