mirror of
https://github.com/apache/nuttx.git
synced 2026-08-27 12:20:46 +00:00
tools/nxstyle: check alignment of statements without a leading keyword
Only lines beginning with a C keyword were checked, so an assignment or a call could sit at any column. Signed-off-by: raiden00pl <raiden00@railab.me> Assisted-by: Claude Code
This commit is contained in:
parent
90b71fb883
commit
c81cc02e83
1 changed files with 41 additions and 0 deletions
|
|
@ -1445,6 +1445,9 @@ int main(int argc, char **argv, char **envp)
|
||||||
int externc_lineno; /* Last line where 'extern "C"' declared */
|
int externc_lineno; /* Last line where 'extern "C"' declared */
|
||||||
bool bexact; /* True: The expected indentation below is exact */
|
bool bexact; /* True: The expected indentation below is exact */
|
||||||
bool bppline; /* True: This line is a pre-processor line */
|
bool bppline; /* True: This line is a pre-processor line */
|
||||||
|
bool blabelline; /* True: This line holds nothing but a label */
|
||||||
|
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 bctrlline; /* True: A control statement starts on this line */
|
||||||
char lastcode; /* Last code character seen on this line */
|
char lastcode; /* Last code character seen on this line */
|
||||||
char prevlastcode; /* Last code character on the preceding line */
|
char prevlastcode; /* Last code character on the preceding line */
|
||||||
|
|
@ -1572,6 +1575,9 @@ int main(int argc, char **argv, char **envp)
|
||||||
brace_indent = 0; /* Indentation of the awaiting keyword */
|
brace_indent = 0; /* Indentation of the awaiting keyword */
|
||||||
bexact = false; /* True: Expected indentation is exact */
|
bexact = false; /* True: Expected indentation is exact */
|
||||||
bppline = false; /* True: This line is a pre-processor line */
|
bppline = false; /* True: This line is a pre-processor line */
|
||||||
|
blabelline = false; /* True: This line holds nothing but a label */
|
||||||
|
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 */
|
bctrlline = false; /* True: A control statement starts here */
|
||||||
lastcode = '\0'; /* Last code character seen on this line */
|
lastcode = '\0'; /* Last code character seen on this line */
|
||||||
prevlastcode = '\0'; /* Last code character on the preceding line */
|
prevlastcode = '\0'; /* Last code character on the preceding line */
|
||||||
|
|
@ -1623,7 +1629,25 @@ int main(int argc, char **argv, char **envp)
|
||||||
bctrlline = false; /* No control statement starts on this line */
|
bctrlline = false; /* No control statement starts on this line */
|
||||||
ctrl_bswitch = false; /* That brace does not open a switch body */
|
ctrl_bswitch = false; /* That brace does not open a switch body */
|
||||||
bppline = false; /* True: This line is a pre-processor line */
|
bppline = false; /* True: This line is a pre-processor line */
|
||||||
|
|
||||||
|
/* A label ends the preceding statement, like a 'case' does */
|
||||||
|
|
||||||
|
blabelline = false;
|
||||||
|
|
||||||
|
if (isalpha((int)line[indent]) != 0 || line[indent] == '_')
|
||||||
|
{
|
||||||
|
int ii = indent;
|
||||||
|
|
||||||
|
while (isalnum((int)line[ii]) != 0 || line[ii] == '_')
|
||||||
|
{
|
||||||
|
ii++;
|
||||||
|
}
|
||||||
|
|
||||||
|
blabelline = line[ii] == ':' && line[ii + 1] != ':';
|
||||||
|
}
|
||||||
|
|
||||||
lastcode = '\0'; /* No code has been seen on this line yet */
|
lastcode = '\0'; /* No code has been seen on this line yet */
|
||||||
|
bstmtstart = bprevstmtend;
|
||||||
rbrace_match = -1; /* No left brace is closed on this line */
|
rbrace_match = -1; /* No left brace is closed on this line */
|
||||||
|
|
||||||
/* Where a statement on this line is expected to begin: two columns in
|
/* Where a statement on this line is expected to begin: two columns in
|
||||||
|
|
@ -3798,6 +3822,22 @@ int main(int argc, char **argv, char **envp)
|
||||||
bexact = bnest > 0 && dnest == 0 && prevpnest == 0 && stmt_indent > 0 &&
|
bexact = bnest > 0 && dnest == 0 && prevpnest == 0 && stmt_indent > 0 &&
|
||||||
bfunctions && bfuncbody;
|
bfunctions && bfuncbody;
|
||||||
|
|
||||||
|
/* A line after one ending in ';', '{', '}' or a label begins a new
|
||||||
|
* statement; anything else continues the previous one.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (lastcode != '\0' && !bppline)
|
||||||
|
{
|
||||||
|
/* A colon ends a statement only in a label, and a line left inside
|
||||||
|
* parentheses is always continued, so a 'for' clause does not.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bprevstmtend = pnest == 0 &&
|
||||||
|
(lastcode == ';' || lastcode == '{' ||
|
||||||
|
lastcode == '}' ||
|
||||||
|
(lastcode == ':' && (bcaseline || blabelline)));
|
||||||
|
}
|
||||||
|
|
||||||
/* A line that follows one ending in ';', '{', '}' or ':' begins a new
|
/* A line that follows one ending in ';', '{', '}' or ':' begins a new
|
||||||
* statement. Anything else is the continuation of the statement on the
|
* statement. Anything else is the continuation of the statement on the
|
||||||
* preceding line and may be aligned freely. Pre-processor lines are
|
* preceding line and may be aligned freely. Pre-processor lines are
|
||||||
|
|
@ -4056,6 +4096,7 @@ int main(int argc, char **argv, char **envp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((bstatm || /* Begins with C keyword */
|
else if ((bstatm || /* Begins with C keyword */
|
||||||
|
(bstmtstart && bexact) || /* Begins a statement */
|
||||||
(line[indent] == '/' &&
|
(line[indent] == '/' &&
|
||||||
bfunctions &&
|
bfunctions &&
|
||||||
line[indent + 1] == '*')) && /* Comment in functions */
|
line[indent + 1] == '*')) && /* Comment in functions */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue