tools/nxstyle.c: Add logic to detect if there is a blank line following the final right brace. sched/: Applied the modified nxstyle to all C file as a test.

This commit is contained in:
Gregory Nutt
2019-10-24 10:49:28 -06:00
parent 2be1153030
commit b5111d2c38
14 changed files with 70 additions and 7 deletions
+2
View File
@@ -178,6 +178,7 @@ static void clock_inittime(void)
#ifndef CONFIG_RTC_HIRES #ifndef CONFIG_RTC_HIRES
clock_basetime(&g_basetime); clock_basetime(&g_basetime);
#endif #endif
#ifndef CONFIG_SCHED_TICKLESS #ifndef CONFIG_SCHED_TICKLESS
g_system_timer = INITIAL_SYSTEM_TIMER_TICKS; g_system_timer = INITIAL_SYSTEM_TIMER_TICKS;
if (g_system_timer > 0) if (g_system_timer > 0)
@@ -197,6 +198,7 @@ static void clock_inittime(void)
} }
} }
#endif /* !CONFIG_SCHED_TICKLESS */ #endif /* !CONFIG_SCHED_TICKLESS */
#else #else
clock_inittimekeeping(); clock_inittimekeeping();
#endif #endif
+1
View File
@@ -122,6 +122,7 @@ int clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
up_rtc_settime(tp); up_rtc_settime(tp);
} }
#endif #endif
leave_critical_section(flags); leave_critical_section(flags);
sinfo("basetime=(%ld,%lu) bias=(%ld,%lu)\n", sinfo("basetime=(%ld,%lu) bias=(%ld,%lu)\n",
+2
View File
@@ -51,6 +51,7 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Note that there cannot be more that CONFIG_MAX_TASKS tasks in total. /* Note that there cannot be more that CONFIG_MAX_TASKS tasks in total.
* However, the number of child status structures may need to be significantly * However, the number of child status structures may need to be significantly
* larger because this number includes the maximum number of tasks that are * larger because this number includes the maximum number of tasks that are
@@ -73,6 +74,7 @@
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
/* Globals are maintained in a structure to minimize name collisions. */ /* Globals are maintained in a structure to minimize name collisions. */
struct child_pool_s struct child_pool_s
+3 -2
View File
@@ -308,8 +308,9 @@ try_again:
} }
else else
{ {
/* Normal tasking environment. */ /* Normal tasking environment.
/* Get the TCB of the currently executing task on this CPU (avoid *
* Get the TCB of the currently executing task on this CPU (avoid
* using this_task() which can recurse. * using this_task() which can recurse.
*/ */
+1
View File
@@ -615,6 +615,7 @@ errout_with_join:
ptcb->joininfo = NULL; ptcb->joininfo = NULL;
errout_with_tcb: errout_with_tcb:
/* Clear group binding */ /* Clear group binding */
if (ptcb && !group_joined) if (ptcb && !group_joined)
+1
View File
@@ -117,6 +117,7 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex)
mutex->nlocks = 1; mutex->nlocks = 1;
} }
#endif #endif
ret = OK; ret = OK;
} }
+1
View File
@@ -582,6 +582,7 @@ void sched_note_spinunlock(FAR struct tcb_s *tcb, FAR volatile void *spinlock)
{ {
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_UNLOCK); note_spincommon(tcb, spinlock, NOTE_SPINLOCK_UNLOCK);
} }
void sched_note_spinabort(FAR struct tcb_s *tcb, FAR volatile void *spinlock) void sched_note_spinabort(FAR struct tcb_s *tcb, FAR volatile void *spinlock)
{ {
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_ABORT); note_spincommon(tcb, spinlock, NOTE_SPINLOCK_ABORT);
+2
View File
@@ -153,6 +153,7 @@ int nxsched_setscheduler(pid_t pid, int policy,
DEBUGVERIFY(sched_sporadic_stop(tcb)); DEBUGVERIFY(sched_sporadic_stop(tcb));
} }
#endif #endif
/* Save the FIFO scheduling parameters */ /* Save the FIFO scheduling parameters */
tcb->flags |= TCB_FLAG_SCHED_FIFO; tcb->flags |= TCB_FLAG_SCHED_FIFO;
@@ -173,6 +174,7 @@ int nxsched_setscheduler(pid_t pid, int policy,
DEBUGVERIFY(sched_sporadic_stop(tcb)); DEBUGVERIFY(sched_sporadic_stop(tcb));
} }
#endif #endif
/* Save the round robin scheduling parameters */ /* Save the round robin scheduling parameters */
tcb->flags |= TCB_FLAG_SCHED_RR; tcb->flags |= TCB_FLAG_SCHED_RR;
-1
View File
@@ -676,7 +676,6 @@ static int nxsem_restoreholderprioB(FAR struct semholder_s *pholder,
if (pholder->htcb == rtcb) if (pholder->htcb == rtcb)
{ {
/* The running task has given up a count on the semaphore */ /* The running task has given up a count on the semaphore */
#if CONFIG_SEM_PREALLOCHOLDERS == 0 #if CONFIG_SEM_PREALLOCHOLDERS == 0
+3
View File
@@ -96,6 +96,7 @@ int nxsem_setprotocol(FAR sem_t *sem, int protocol)
switch (protocol) switch (protocol)
{ {
case SEM_PRIO_NONE: case SEM_PRIO_NONE:
/* Disable priority inheritance */ /* Disable priority inheritance */
sem->flags |= PRIOINHERIT_FLAGS_DISABLE; sem->flags |= PRIOINHERIT_FLAGS_DISABLE;
@@ -106,12 +107,14 @@ int nxsem_setprotocol(FAR sem_t *sem, int protocol)
return OK; return OK;
case SEM_PRIO_INHERIT: case SEM_PRIO_INHERIT:
/* Enable priority inheritance (dangerous) */ /* Enable priority inheritance (dangerous) */
sem->flags &= ~PRIOINHERIT_FLAGS_DISABLE; sem->flags &= ~PRIOINHERIT_FLAGS_DISABLE;
return OK; return OK;
case SEM_PRIO_PROTECT: case SEM_PRIO_PROTECT:
/* Not yet supported */ /* Not yet supported */
return -ENOSYS; return -ENOSYS;
+1
View File
@@ -309,6 +309,7 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
return -ECANCELED; return -ECANCELED;
} }
#endif #endif
/* Save the set of pending signals to wait for */ /* Save the set of pending signals to wait for */
rtcb->sigwaitmask = *set; rtcb->sigwaitmask = *set;
+6 -4
View File
@@ -92,10 +92,12 @@
* (2) the number of symbols in that table. This information is currently * (2) the number of symbols in that table. This information is currently
* provided to 'exec()' from 'exec[l|v]()' via NuttX configuration settings: * provided to 'exec()' from 'exec[l|v]()' via NuttX configuration settings:
* *
* CONFIG_LIBC_EXECFUNCS : Enable exec[l|v] support * CONFIG_LIBC_EXECFUNCS : Enable exec[l|v] support
* CONFIG_EXECFUNCS_HAVE_SYMTAB : Defined if there is a pre-defined symbol table * CONFIG_EXECFUNCS_HAVE_SYMTAB : Defined if there is a pre-defined
* CONFIG_EXECFUNCS_SYMTAB_ARRAY : Symbol table name used by exec[l|v] * symbol table
* CONFIG_EXECFUNCS_NSYMBOLS_VAR : Variable holding number of symbols in the table * CONFIG_EXECFUNCS_SYMTAB_ARRAY : Symbol table name used by exec[l|v]
* CONFIG_EXECFUNCS_NSYMBOLS_VAR : Variable holding number of symbols
* in the table
* *
* As a result of the above, the current implementations of 'execl()' and * As a result of the above, the current implementations of 'execl()' and
* 'execv()' suffer from some incompatibilities that may or may not be * 'execv()' suffer from some incompatibilities that may or may not be
+2
View File
@@ -222,12 +222,14 @@ int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...)
{ {
wdog->parm[i] = va_arg(ap, wdparm_t); wdog->parm[i] = va_arg(ap, wdparm_t);
} }
#ifdef CONFIG_DEBUG_FEATURES #ifdef CONFIG_DEBUG_FEATURES
for (; i < CONFIG_MAX_WDOGPARMS; i++) for (; i < CONFIG_MAX_WDOGPARMS; i++)
{ {
wdog->parm[i] = 0; wdog->parm[i] = 0;
} }
#endif #endif
va_end(ap); va_end(ap);
/* Calculate delay+1, forcing the delay into a range that we can handle */ /* Calculate delay+1, forcing the delay into a range that we can handle */
+45
View File
@@ -129,6 +129,7 @@ int main(int argc, char **argv, char **envp)
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 lbrace_lineno; /* Line number of last left brace */
int rbrace_lineno; /* Last line containing a right brace */
int externc_lineno; /* Last line where 'extern "C"' declared */ int externc_lineno; /* Last line where 'extern "C"' declared */
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 */
@@ -213,6 +214,7 @@ int main(int argc, char **argv, char **envp)
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 */ lbrace_lineno = -1; /* Line number of last left brace */
rbrace_lineno = -1; /* Last line containine a right brace */
externc_lineno = -1; /* Last line where 'extern "C"' declared */ externc_lineno = -1; /* Last line where 'extern "C"' declared */
/* Process each line in the input stream */ /* Process each line in the input stream */
@@ -291,6 +293,47 @@ int main(int argc, char **argv, char **envp)
fprintf(stderr, fprintf(stderr,
"Missing file header comment block at line 1\n"); "Missing file header comment block at line 1\n");
} }
/* Check for a blank line following a right brace */
if (bfunctions && lineno == rbrace_lineno + 1)
{
/* Check if this line contains a right brace. A right brace
* must be followed by 'else', 'while', 'break', a blank line,
* another right brace, or a pre-processor directive like #endif
*/
if (strchr(line, '}') == NULL && line[n] != '#' &&
strncmp(&line[n], "else", 4) != 0 &&
strncmp(&line[n], "while", 5) != 0 &&
strncmp(&line[n], "break", 5) != 0)
{
fprintf(stderr,
"Right brace must be followed by a blank line at line %d\n",
rbrace_lineno);
}
/* If the right brace is followed by a pre-proceeor command
* like #endif (but not #else or #elif), then set the right
* brace line number to the line number of the pre-processor
* command (it then must be followed by a blank line)
*/
if (line[n] == '#')
{
int ii;
for (ii = n + 1; line[ii] != '\0' && isspace(line[ii]); ii++)
{
}
if (strncmp(&line[ii], "else", 4) != 0 &&
strncmp(&line[ii], "elif", 4) != 0)
{
rbrace_lineno = lineno;
}
}
}
} }
/* STEP 1: Find the indentation level and the start of real stuff on /* STEP 1: Find the indentation level and the start of real stuff on
@@ -1023,6 +1066,8 @@ int main(int argc, char **argv, char **envp)
"Blank line precedes right brace at line %d\n", "Blank line precedes right brace at line %d\n",
lineno); lineno);
} }
rbrace_lineno = lineno;
} }
break; break;