This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 828a786995a tools/nxstyle: let an alternative branch hold statements
before its braces
828a786995a is described below
commit 828a786995aac5fdf0eb468736dc28571edfbbdc
Author: raiden00pl <[email protected]>
AuthorDate: Mon Jul 27 12:20:13 2026 +0200
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 <[email protected]>
Assisted-by: Claude Code
---
tools/nxstyle.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 4c58c8bedde..1f9a8e80786 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -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 */