Skip to content

Commit 76f57cf

Browse files
committed
Make fmtscan skip inline assembly
Previously, fmtscan would report spelling in inline assembly and block committing. Closes: #292 Change-Id: Ia65d8041c8ee46084ecff52a28c0d8ec3976c528
1 parent 6a93f2f commit 76f57cf

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

tools/fmtscan.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,49 @@ 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)
633+
{
634+
get_char_t ch = get_char(p);
635+
if (ch != 's')
636+
goto check_s_failed;
637+
if (UNLIKELY(ch == PARSER_EOF))
638+
return ch;
639+
ch = get_char(p);
640+
if (ch != 'm')
641+
goto check_m_failed;
642+
if (UNLIKELY(ch == PARSER_EOF))
643+
return ch;
644+
645+
int paren = 0;
646+
do {
647+
ch = get_char(p);
648+
if (ch == '\n') {
649+
lines++;
650+
lineno++;
651+
continue;
652+
}
653+
if (ch == '/') {
654+
get_char_t ret = skip_comments(p);
655+
if (LIKELY(ret == PARSER_COMMENT_FOUND))
656+
continue;
657+
if (UNLIKELY(ret == PARSER_EOF))
658+
return ret;
659+
}
660+
if (UNLIKELY(ch == PARSER_EOF))
661+
return ch;
662+
/* Increase paren by 1 if ch is '(' and decrease by 1 if ch is ')'. */
663+
ch ^= '('; /* This results 0, 1, or other for '(', ')', or other. */
664+
paren += !ch - (ch == 1);
665+
} while (paren);
666+
return PARSER_COMMENT_FOUND;
667+
668+
check_m_failed:
669+
unget_char(p);
670+
check_s_failed:
671+
unget_char(p);
672+
return PARSER_OK;
673+
}
674+
632675
/* Parse an integer value.
633676
* Since the Linux kernel does not support floats or doubles, only decimal,
634677
* octal, and hexadecimal formats are handled.
@@ -743,6 +786,23 @@ static get_char_t parse_identifier(parser_t *restrict p,
743786
}
744787
}
745788

789+
/* Parse an potential inline assembly. */
790+
static get_char_t parse_inline_asm(parser_t *restrict p,
791+
token_t *restrict t,
792+
get_char_t ch)
793+
{
794+
get_char_t ret = skip_inline_asm(p);
795+
796+
if (ret == PARSER_COMMENT_FOUND) {
797+
ret |= PARSER_CONTINUE;
798+
return ret;
799+
}
800+
if (UNLIKELY(ret == PARSER_EOF))
801+
return ret;
802+
803+
return parse_identifier(p, t, ch);
804+
}
805+
746806
/* Process escape sequences at the end of a string literal.
747807
* Transformations:
748808
* "foo\n" becomes "foo"
@@ -1112,7 +1172,7 @@ static get_token_action_t get_token_actions[] = {
11121172
['|'] = parse_op,
11131173
['&'] = parse_op,
11141174
['-'] = parse_minus,
1115-
['a'] = parse_identifier,
1175+
['a'] = parse_inline_asm,
11161176
['b'] = parse_identifier,
11171177
['c'] = parse_identifier,
11181178
['d'] = parse_identifier,

0 commit comments

Comments
 (0)