tools/nxstyle.c: Add logic to detect a blank line following a left brace or a blank line preceding a right brace.

This commit is contained in:
Gregory Nutt
2019-03-10 09:53:33 -06:00
parent 8be37f0a15
commit f6b9fe5b14
3 changed files with 30 additions and 5 deletions
-1
View File
@@ -140,7 +140,6 @@ void sched_resume_scheduler(FAR struct tcb_s *tcb)
&g_cpu_irqlock); &g_cpu_irqlock);
} }
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
} }
#endif /* CONFIG_RR_INTERVAL > 0 || CONFIG_SCHED_RESUMESCHEDULER */ #endif /* CONFIG_RR_INTERVAL > 0 || CONFIG_SCHED_RESUMESCHEDULER */
-1
View File
@@ -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, sq_addafter((FAR sq_entry_t *)prev, (FAR sq_entry_t *)wdog,
&g_wdactivelist); &g_wdactivelist);
} }
} }
+30 -3
View File
@@ -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 comment_lineno; /* Line on which the last one line comment was closed */
int blank_lineno; /* Line number of the last blank line */ int blank_lineno; /* Line number of the last blank line */
int noblank_lineno; /* A blank line is not needed after this 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 linelen; /* Length of the line */
int maxline; /* Lines longer that this generate warnings */ int maxline; /* Lines longer that this generate warnings */
int n; 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 */ comment_lineno = -1; /* Line on which the last one line comment was closed */
blank_lineno = -1; /* Line number of the last blank line */ blank_lineno = -1; /* Line number of the last blank line */
noblank_lineno = -1; /* A blank line is not needed after this 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 */ /* 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); 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; blank_lineno = lineno;
continue; continue;
@@ -768,11 +775,14 @@ int main(int argc, char **argv, char **envp)
/* Suppress error for comment following a left brace */ /* Suppress error for comment following a left brace */
noblank_lineno = lineno; noblank_lineno = lineno;
lbrace_lineno = lineno;
} }
break; break;
case '}': case '}':
{ {
/* Decrement the brace nesting level */
if (bnest < 1) if (bnest < 1)
{ {
fprintf(stderr, "Unmatched right brace at line %d:%d\n", lineno, n); 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) if (dnest < 3)
{ {
dnest = 0; dnest = 0;
@@ -796,6 +808,8 @@ int main(int argc, char **argv, char **envp)
dnest--; dnest--;
} }
/* The right brace should be on a separate line */
if (n > indent) if (n > indent)
{ {
if (dnest == 0) if (dnest == 0)
@@ -805,9 +819,12 @@ int main(int argc, char **argv, char **envp)
lineno, n); lineno, n);
} }
} }
else if (line[n + 1] != '\n' &&
line[n + 1] != ',' && /* Check for garbage following the left brace */
line[n + 1] != ';')
if (line[n + 1] != '\n' &&
line[n + 1] != ',' &&
line[n + 1] != ';')
{ {
/* One case where there may be garbage after the right /* One case where there may be garbage after the right
* bracket is, for example, when declaring a until or * bracket is, for example, when declaring a until or
@@ -826,6 +843,16 @@ int main(int argc, char **argv, char **envp)
lineno, n); 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; break;