Skip to content

Commit e96309f

Browse files
committed
Make fmtscan support '__asm__' alternative keyword
According to the GCC documentation, the 'asm' keyword is a GNU extension and the alternative '__asm__' can be used when writing code compiled with '-ansi' and various '-std' options. Change-Id: Icb6c052a92894839b99640641964f0e99e16eb30
1 parent c0babda commit e96309f

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

tools/fmtscan.c

+44-3
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ static get_char_t skip_macros(parser_t *p)
629629
return PARSER_EOF;
630630
}
631631

632-
static get_char_t skip_inline_asm(parser_t *p)
632+
static get_char_t skip_inline_asm(parser_t *p, bool underscore)
633633
{
634634
get_char_t ch = get_char(p);
635635
if (ch != 's')
@@ -642,6 +642,19 @@ static get_char_t skip_inline_asm(parser_t *p)
642642
if (UNLIKELY(ch == PARSER_EOF))
643643
return ch;
644644

645+
if (underscore) {
646+
ch = get_char(p);
647+
if (ch != '_')
648+
goto check_underline_1_failed;
649+
if (UNLIKELY(ch == PARSER_EOF))
650+
return ch;
651+
ch = get_char(p);
652+
if (ch != '_')
653+
goto check_underline_2_failed;
654+
if (UNLIKELY(ch == PARSER_EOF))
655+
return ch;
656+
}
657+
645658
int paren = 0;
646659
do {
647660
ch = get_char(p);
@@ -665,6 +678,10 @@ static get_char_t skip_inline_asm(parser_t *p)
665678
} while (paren);
666679
return PARSER_COMMENT_FOUND;
667680

681+
check_underline_2_failed:
682+
unget_char(p);
683+
check_underline_1_failed:
684+
unget_char(p);
668685
check_m_failed:
669686
unget_char(p);
670687
check_s_failed:
@@ -791,7 +808,31 @@ static get_char_t parse_inline_asm(parser_t *restrict p,
791808
token_t *restrict t,
792809
get_char_t ch)
793810
{
794-
get_char_t ret = skip_inline_asm(p);
811+
get_char_t ret = skip_inline_asm(p, false);
812+
813+
if (ret == PARSER_COMMENT_FOUND) {
814+
ret |= PARSER_CONTINUE;
815+
return ret;
816+
}
817+
if (UNLIKELY(ret == PARSER_EOF))
818+
return ret;
819+
820+
return parse_identifier(p, t, ch);
821+
}
822+
823+
/* Parse an potential inline assembly wraped with double underscores. */
824+
static get_char_t parse_inline_asm_underscore(parser_t *restrict p,
825+
token_t *restrict t,
826+
get_char_t ch)
827+
{
828+
get_char_t ret = get_char(p);
829+
if (ret != '_') {
830+
unget_char(p);
831+
return parse_identifier(p, t, ch);
832+
}
833+
if (UNLIKELY(ret == PARSER_EOF))
834+
return ret;
835+
ret = skip_inline_asm(p, true);
795836

796837
if (ret == PARSER_COMMENT_FOUND) {
797838
ret |= PARSER_CONTINUE;
@@ -1224,7 +1265,7 @@ static get_token_action_t get_token_actions[] = {
12241265
['X'] = parse_identifier,
12251266
['Y'] = parse_identifier,
12261267
['Z'] = parse_identifier,
1227-
['_'] = parse_identifier,
1268+
['_'] = parse_inline_asm_underscore,
12281269
['"'] = parse_literal_string,
12291270
['\''] = parse_literal_char,
12301271
['\\'] = parse_backslash,

0 commit comments

Comments
 (0)