tools/nxstyle.c: Fix error in conditional logic that was preventing detection bad brace alignment. Add logic to handle alignment of braces in data initializators which following slightly different indentation rules.

This commit is contained in:
Gregory Nutt
2019-06-30 10:35:10 -06:00
parent 5653b9a2af
commit bde0509cae
10 changed files with 122 additions and 90 deletions
+6
View File
@@ -90,6 +90,7 @@
****************************************************************************/ ****************************************************************************/
/* Task Lists ***************************************************************/ /* Task Lists ***************************************************************/
/* The state of a task is indicated both by the task_state field of the TCB /* The state of a task is indicated both by the task_state field of the TCB
* and by a series of task lists. All of these tasks lists are declared * and by a series of task lists. All of these tasks lists are declared
* below. Although it is not always necessary, most of these lists are * below. Although it is not always necessary, most of these lists are
@@ -401,6 +402,7 @@ void nx_start(void)
g_nx_initstate = OSINIT_BOOT; g_nx_initstate = OSINIT_BOOT;
/* Initialize RTOS Data ***************************************************/ /* Initialize RTOS Data ***************************************************/
/* Initialize all task lists */ /* Initialize all task lists */
dq_init(&g_readytorun); dq_init(&g_readytorun);
@@ -747,6 +749,7 @@ void nx_start(void)
#endif #endif
/* IDLE Group Initialization **********************************************/ /* IDLE Group Initialization **********************************************/
/* Announce that the CPU0 IDLE task has started */ /* Announce that the CPU0 IDLE task has started */
sched_note_start(&g_idletcb[0].cmn); sched_note_start(&g_idletcb[0].cmn);
@@ -788,6 +791,7 @@ void nx_start(void)
} }
/* Start SYSLOG ***********************************************************/ /* Start SYSLOG ***********************************************************/
/* Late initialization of the system logging device. Some SYSLOG channel /* Late initialization of the system logging device. Some SYSLOG channel
* must be initialized late in the initialization sequence because it may * must be initialized late in the initialization sequence because it may
* depend on having IDLE task file structures setup. * depend on having IDLE task file structures setup.
@@ -815,6 +819,7 @@ void nx_start(void)
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
/* Bring Up the System ****************************************************/ /* Bring Up the System ****************************************************/
/* The OS is fully initialized and we are beginning multi-tasking */ /* The OS is fully initialized and we are beginning multi-tasking */
g_nx_initstate = OSINIT_OSREADY; g_nx_initstate = OSINIT_OSREADY;
@@ -831,6 +836,7 @@ void nx_start(void)
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
/* The IDLE Loop **********************************************************/ /* The IDLE Loop **********************************************************/
/* When control is return to this point, the system is idle. */ /* When control is return to this point, the system is idle. */
sinfo("CPU0: Beginning Idle Loop\n"); sinfo("CPU0: Beginning Idle Loop\n");
+6 -4
View File
@@ -57,8 +57,8 @@ struct irqchain_s
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
/* g_irqchainpool is a list of pre-allocated irq chain. The number of irq chains /* g_irqchainpool is a list of pre-allocated irq chain. The number of irq
* in the pool is a configuration item. * chains in the pool is a configuration item.
*/ */
static struct irqchain_s g_irqchainpool[CONFIG_PREALLOC_IRQCHAIN]; static struct irqchain_s g_irqchainpool[CONFIG_PREALLOC_IRQCHAIN];
@@ -255,14 +255,16 @@ int irqchain_detach(int irq, xcpt_t isr, FAR void *arg)
prev->next = curr->next; prev->next = curr->next;
} }
sq_addlast((FAR struct sq_entry_s *)curr, &g_irqchainfreelist); sq_addlast((FAR struct sq_entry_s *)curr,
&g_irqchainfreelist);
first = g_irqvector[ndx].arg; first = g_irqvector[ndx].arg;
if (first->next == NULL) if (first->next == NULL)
{ {
g_irqvector[ndx].handler = first->handler; g_irqvector[ndx].handler = first->handler;
g_irqvector[ndx].arg = first->arg; g_irqvector[ndx].arg = first->arg;
sq_addlast((FAR struct sq_entry_s *)first, &g_irqchainfreelist); sq_addlast((FAR struct sq_entry_s *)first,
&g_irqchainfreelist);
} }
ret = OK; ret = OK;
+5 -5
View File
@@ -59,12 +59,12 @@
* Description: * Description:
* The function pthread_mutex_trylock() is identical to pthread_mutex_lock() * The function pthread_mutex_trylock() is identical to pthread_mutex_lock()
* except that if the mutex object referenced by mutex is currently locked * except that if the mutex object referenced by mutex is currently locked
* (by any thread, including the current thread), the call returns immediately * (by any thread, including the current thread), the call returns
* with the errno EBUSY. * immediately with the errno EBUSY.
* *
* If a signal is delivered to a thread waiting for a mutex, upon return from * If a signal is delivered to a thread waiting for a mutex, upon return
* the signal handler the thread resumes waiting for the mutex as if it was * from the signal handler the thread resumes waiting for the mutex as if
* not interrupted. * it was not interrupted.
* *
* Input Parameters: * Input Parameters:
* mutex - A reference to the mutex to be locked. * mutex - A reference to the mutex to be locked.
+10 -9
View File
@@ -94,13 +94,14 @@ static inline bool pthread_mutex_islocked(FAR struct pthread_mutex_s *mutex)
* mutex's type attribute. If there are threads blocked on the mutex object * mutex's type attribute. If there are threads blocked on the mutex object
* referenced by mutex when pthread_mutex_unlock() is called, resulting in * referenced by mutex when pthread_mutex_unlock() is called, resulting in
* the mutex becoming available, the scheduling policy is used to determine * the mutex becoming available, the scheduling policy is used to determine
* which thread shall acquire the mutex. (In the case of PTHREAD_MUTEX_RECURSIVE * which thread shall acquire the mutex. (In the case of
* mutexes, the mutex becomes available when the count reaches zero and the * PTHREAD_MUTEX_RECURSIVE mutexes, the mutex becomes available when the
* calling thread no longer has any locks on this mutex). * count reaches zero and the calling thread no longer has any locks on
* this mutex).
* *
* If a signal is delivered to a thread waiting for a mutex, upon return from * If a signal is delivered to a thread waiting for a mutex, upon return
* the signal handler the thread resumes waiting for the mutex as if it was * from the signal handler the thread resumes waiting for the mutex as if
* not interrupted. * it was not interrupted.
* *
* Input Parameters: * Input Parameters:
* None * None
@@ -203,9 +204,9 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->nlocks > 1) if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->nlocks > 1)
{ {
/* This is a recursive mutex and we there are multiple locks held. Retain /* This is a recursive mutex and we there are multiple locks held.
* the mutex lock, just decrement the count of locks held, and return * Retain the mutex lock, just decrement the count of locks held,
* success. * and return success.
*/ */
mutex->nlocks--; mutex->nlocks--;
+10 -9
View File
@@ -204,13 +204,14 @@ static void nxsig_abnormal_termination(int signo)
* "When cancelability is disabled, all cancels are held pending * "When cancelability is disabled, all cancels are held pending
* in the target thread until the thread changes the cancelability. * in the target thread until the thread changes the cancelability.
* When cancelability is deferred, all cancels are held pending in * When cancelability is deferred, all cancels are held pending in
* the target thread until the thread changes the cancelability, calls * the target thread until the thread changes the cancelability,
* a function which is a cancellation point or calls pthread_testcancel(), * calls a function which is a cancellation point or calls
* thus creating a cancellation point. When cancelability is asynchronous, * pthread_testcancel(), thus creating a cancellation point. When
* all cancels are acted upon immediately, interrupting the thread with its * cancelability is asynchronous, all cancels are acted upon
* processing." * immediately, interrupting the thread with its processing."
* *
* REVISIT: Does this rule apply to equally to both SIGKILL and SIGINT? * REVISIT: Does this rule apply to equally to both SIGKILL and
* SIGINT?
*/ */
rtcb->flags |= TCB_FLAG_CANCEL_PENDING; rtcb->flags |= TCB_FLAG_CANCEL_PENDING;
@@ -538,7 +539,7 @@ bool nxsig_iscatchable(int signo)
* *
****************************************************************************/ ****************************************************************************/
_sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction) _sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction)
{ {
FAR struct task_group_s *group; FAR struct task_group_s *group;
_sa_handler_t handler = SIG_IGN; _sa_handler_t handler = SIG_IGN;
@@ -584,8 +585,8 @@ bool nxsig_iscatchable(int signo)
* Name: nxsig_default_initialize * Name: nxsig_default_initialize
* *
* Description: * Description:
* Set all signals to their default action. This is called from nxtask_start * Set all signals to their default action. This is called from
* to configure the newly started task. * nxtask_start() to configure the newly started task.
* *
* Input Parameters: * Input Parameters:
* tcb - Identifies the thread associated with the default handlers * tcb - Identifies the thread associated with the default handlers
+2 -1
View File
@@ -130,7 +130,8 @@ int ppoll(FAR struct pollfd *fds, nfds_t nfds,
if (timeout_ts) if (timeout_ts)
{ {
timeout = timeout_ts->tv_sec * 1000 + timeout_ts->tv_nsec / 1000000; timeout = timeout_ts->tv_sec * 1000 +
timeout_ts->tv_nsec / 1000000;
} }
ret = poll(fds, nfds, timeout); ret = poll(fds, nfds, timeout);
+27 -6
View File
@@ -429,6 +429,11 @@ int main(int argc, char **argv, char **envp)
strncmp(&line[indent], "void ", 5) == 0 || strncmp(&line[indent], "void ", 5) == 0 ||
strncmp(&line[indent], "volatile ", 9) == 0) strncmp(&line[indent], "volatile ", 9) == 0)
{ {
/* bfunctions: True: Processing private or public functions.
* bnest: Brace nesting level on this line
* dnest: Data declaration nesting level on this line
*/
/* REVISIT: Also picks up function return types */ /* REVISIT: Also picks up function return types */
/* REVISIT: Logic problem for nested data/function declarations */ /* REVISIT: Logic problem for nested data/function declarations */
@@ -843,7 +848,7 @@ int main(int argc, char **argv, char **envp)
{ {
if (n > indent) if (n > indent)
{ {
/* REVISIT: dest is always > 0 here if bfunctions == false */ /* REVISIT: dnest is always > 0 here if bfunctions == false */
if (dnest == 0 || !bfunctions) if (dnest == 0 || !bfunctions)
{ {
@@ -1525,7 +1530,7 @@ int main(int argc, char **argv, char **envp)
/* Check for various alignment outside of the comment block */ /* Check for various alignment outside of the comment block */
else if ((ncomment > 0 || prevncomment > 0) && !bstring) else if ((ncomment == 0 && prevncomment == 0) && !bstring)
{ {
if (indent == 0 && strchr("\n#{}", line[0]) == NULL) if (indent == 0 && strchr("\n#{}", line[0]) == NULL)
{ {
@@ -1564,9 +1569,17 @@ int main(int argc, char **argv, char **envp)
} }
else if (line[indent] == '{') else if (line[indent] == '{')
{ {
/* REVISIT: False alarms in data initializers and switch statements */ /* REVISIT: Possible false alarms in compound statements
* without a preceding conditional. That usage often violates
* the coding standard.
*/
if ((indent & 3) != 0 && !bswitch && dnest == 0) if (!bfunctions && (indent & 1) != 0)
{
fprintf(stderr, "Bad left brace alignment at line %d:%d\n",
lineno, indent);
}
else if ((indent & 3) != 0 && !bswitch && dnest == 0)
{ {
fprintf(stderr, "Bad left brace alignment at line %d:%d\n", fprintf(stderr, "Bad left brace alignment at line %d:%d\n",
lineno, indent); lineno, indent);
@@ -1574,9 +1587,17 @@ int main(int argc, char **argv, char **envp)
} }
else if (line[indent] == '}') else if (line[indent] == '}')
{ {
/* REVISIT: False alarms in data initializers and switch statements */ /* REVISIT: Possible false alarms in compound statements
* without a preceding conditional. That usage often violates
* the coding standard.
*/
if ((indent & 3) != 0 && !bswitch && prevdnest == 0) if (!bfunctions && (indent & 1) != 0)
{
fprintf(stderr, "right left brace alignment at line %d:%d\n",
lineno, indent);
}
else if ((indent & 3) != 0 && !bswitch && prevdnest == 0)
{ {
fprintf(stderr, "Bad right brace alignment at line %d:%d\n", fprintf(stderr, "Bad right brace alignment at line %d:%d\n",
lineno, indent); lineno, indent);