From f6b9fe5b149a728ac7b3afff1a429f01c03cee90 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Mar 2019 09:53:33 -0600 Subject: [PATCH] tools/nxstyle.c: Add logic to detect a blank line following a left brace or a blank line preceding a right brace. --- sched/sched/sched_resumescheduler.c | 1 - sched/wdog/wd_start.c | 1 - tools/nxstyle.c | 33 ++++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/sched/sched/sched_resumescheduler.c b/sched/sched/sched_resumescheduler.c index 58b5a13210..caad995025 100644 --- a/sched/sched/sched_resumescheduler.c +++ b/sched/sched/sched_resumescheduler.c @@ -140,7 +140,6 @@ void sched_resume_scheduler(FAR struct tcb_s *tcb) &g_cpu_irqlock); } #endif /* CONFIG_SMP */ - } #endif /* CONFIG_RR_INTERVAL > 0 || CONFIG_SCHED_RESUMESCHEDULER */ diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c index ab38bbcbc3..6f4fa2f907 100644 --- a/sched/wdog/wd_start.c +++ b/sched/wdog/wd_start.c @@ -353,7 +353,6 @@ int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...) sq_addafter((FAR sq_entry_t *)prev, (FAR sq_entry_t *)wdog, &g_wdactivelist); - } } diff --git a/tools/nxstyle.c b/tools/nxstyle.c index 117a9cb4d4..127adb8a1f 100644 --- a/tools/nxstyle.c +++ b/tools/nxstyle.c @@ -124,6 +124,7 @@ int main(int argc, char **argv, char **envp) int comment_lineno; /* Line on which the last one line comment was closed */ int blank_lineno; /* Line number of the last blank line */ int noblank_lineno; /* A blank line is not needed after this line */ + int lbrace_lineno; /* Line number of last left brace */ int linelen; /* Length of the line */ int maxline; /* Lines longer that this generate warnings */ int n; @@ -186,6 +187,7 @@ int main(int argc, char **argv, char **envp) comment_lineno = -1; /* Line on which the last one line comment was closed */ blank_lineno = -1; /* Line number of the last blank line */ noblank_lineno = -1; /* A blank line is not needed after this line */ + lbrace_lineno = -1; /* Line number of last left brace */ /* Process each line in the input stream */ @@ -221,6 +223,11 @@ int main(int argc, char **argv, char **envp) { fprintf(stderr, "Too many blank lines at line %d\n", lineno); } + else if (lineno == lbrace_lineno + 1) + { + fprintf(stderr, "Blank line follows left brace at line %d\n", + lineno); + } blank_lineno = lineno; continue; @@ -768,11 +775,14 @@ int main(int argc, char **argv, char **envp) /* Suppress error for comment following a left brace */ noblank_lineno = lineno; + lbrace_lineno = lineno; } break; case '}': { + /* Decrement the brace nesting level */ + if (bnest < 1) { fprintf(stderr, "Unmatched right brace at line %d:%d\n", lineno, n); @@ -787,6 +797,8 @@ int main(int argc, char **argv, char **envp) } } + /* Decrement the declaration nesting level */ + if (dnest < 3) { dnest = 0; @@ -796,6 +808,8 @@ int main(int argc, char **argv, char **envp) dnest--; } + /* The right brace should be on a separate line */ + if (n > indent) { if (dnest == 0) @@ -805,9 +819,12 @@ int main(int argc, char **argv, char **envp) lineno, n); } } - else if (line[n + 1] != '\n' && - line[n + 1] != ',' && - line[n + 1] != ';') + + /* Check for garbage following the left brace */ + + if (line[n + 1] != '\n' && + line[n + 1] != ',' && + line[n + 1] != ';') { /* One case where there may be garbage after the right * bracket is, for example, when declaring a until or @@ -826,6 +843,16 @@ int main(int argc, char **argv, char **envp) lineno, n); } } + + /* The right brace should not be preceded with a a blank line */ + + + if (lineno == blank_lineno + 1) + { + fprintf(stderr, + "Blank line precedes right brace at line %d\n", + lineno); + } } break;