mirror of
https://github.com/apache/nuttx.git
synced 2026-08-27 04:10:40 +00:00
tools/nxstyle: let an alternative branch hold statements before its braces
Alternatives selected by conditional compilation share the braces that follow, and a branch may hold statements before reaching its condition. Signed-off-by: raiden00pl <raiden00@railab.me> Assisted-by: Claude Code
This commit is contained in:
parent
b986fb8ee5
commit
828a786995
1 changed files with 21 additions and 2 deletions
|
|
@ -1470,6 +1470,7 @@ int main(int argc, char **argv, char **envp)
|
|||
bool bstmtstart; /* True: A new statement begins on this line */
|
||||
bool bprevstmtend; /* True: The preceding line of code ended a statement */
|
||||
bool bctrlline; /* True: A control statement starts on this line */
|
||||
bool bppalt; /* True: In an alternative branch awaiting braces */
|
||||
char lastcode; /* Last code character seen on this line */
|
||||
char prevlastcode; /* Last code character on the preceding line */
|
||||
int prevcodeindent; /* Indentation of the preceding line of code */
|
||||
|
|
@ -1601,6 +1602,7 @@ int main(int argc, char **argv, char **envp)
|
|||
bstmtstart = true; /* True: A statement begins on this line */
|
||||
bprevstmtend = true; /* True: The preceding code ended a statement */
|
||||
bctrlline = false; /* True: A control statement starts here */
|
||||
bppalt = false; /* True: Alternative branch awaiting braces */
|
||||
lastcode = '\0'; /* Last code character seen on this line */
|
||||
prevlastcode = '\0'; /* Last code character on the preceding line */
|
||||
prevcodeindent = 0; /* Indentation of the preceding line of code */
|
||||
|
|
@ -1984,6 +1986,17 @@ int main(int argc, char **argv, char **envp)
|
|||
|
||||
bppline = true;
|
||||
|
||||
/* Alternative branches share the braces that close the construct,
|
||||
* and may hold statements of their own before reaching them.
|
||||
*/
|
||||
|
||||
if (brace_kw != NULL &&
|
||||
(strncmp(&line[indent], "#else", 5) == 0 ||
|
||||
strncmp(&line[indent], "#elif", 5) == 0))
|
||||
{
|
||||
bppalt = true;
|
||||
}
|
||||
|
||||
/* Suppress error for comment following conditional compilation */
|
||||
|
||||
noblank_lineno = lineno;
|
||||
|
|
@ -3767,14 +3780,20 @@ int main(int argc, char **argv, char **envp)
|
|||
* an 'else if', or alternatives sharing the braces that follow.
|
||||
*/
|
||||
|
||||
else if (!bctrlline)
|
||||
else if (!bctrlline && !bppalt)
|
||||
{
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"Missing braces after '%s'", brace_kw);
|
||||
ERROR(buffer, lineno, indent);
|
||||
}
|
||||
|
||||
brace_kw = NULL;
|
||||
/* An alternative branch may hold statements first */
|
||||
|
||||
if (line[indent] == '{' || bctrlline || !bppalt)
|
||||
{
|
||||
brace_kw = NULL;
|
||||
bppalt = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Has the header ended on this line? If so, see what follows */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue