tools/nxstyle: fix wrong error reports for if statements
* Fix nxstyle check so it does not report error on comments on the same line as if statements * Rework if statement checks * Report warning instead of error for is statements check fail
This commit is contained in:
parent
b14dc8f8ae
commit
d59fbfdbdc
|
@ -1225,6 +1225,7 @@ int main(int argc, char **argv, char **envp)
|
|||
bswitch = false; /* True: Within a switch statement */
|
||||
bstring = false; /* True: Within a string */
|
||||
bexternc = false; /* True: Within 'extern "C"' */
|
||||
bif = false; /* True: This line is beginning of a 'if' statement */
|
||||
ppline = PPLINE_NONE; /* > 0: The next line the continuation of a
|
||||
* pre-processor command */
|
||||
rhcomment = 0; /* Indentation of Comment to the right of code
|
||||
|
@ -1258,7 +1259,6 @@ int main(int argc, char **argv, char **envp)
|
|||
bstatm = false; /* True: This line is beginning of a
|
||||
* statement */
|
||||
bfor = false; /* REVISIT: Implies for() is all on one line */
|
||||
bif = false; /* True: This line is beginning of a 'if' statement */
|
||||
|
||||
/* If we are not in a comment, then this certainly is not a right-hand
|
||||
* comment.
|
||||
|
@ -2260,6 +2260,13 @@ int main(int argc, char **argv, char **envp)
|
|||
}
|
||||
}
|
||||
|
||||
/* Allow comments on the same line as the if statement */
|
||||
|
||||
if (bif == true)
|
||||
{
|
||||
bif = false;
|
||||
}
|
||||
|
||||
n++;
|
||||
continue;
|
||||
}
|
||||
|
@ -2630,9 +2637,11 @@ int main(int argc, char **argv, char **envp)
|
|||
ERROR("Space precedes right parenthesis", lineno, n);
|
||||
}
|
||||
|
||||
if (bif == true && pnest == 0 && line[n + 1] != '\n')
|
||||
/* Unset bif if last parenthesis is closed */
|
||||
|
||||
if (bif == true && pnest == 0)
|
||||
{
|
||||
ERROR("If statement followed by garbage", lineno, n);
|
||||
bif = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -3105,6 +3114,15 @@ int main(int argc, char **argv, char **envp)
|
|||
if (m > 1 && isspace((int)line[m - 1]) &&
|
||||
line[m - 1] != '\n' && line[m - 1] != '\r')
|
||||
{
|
||||
/* Report warning on if statement only is pnest is 0
|
||||
* This takes into consideration the multiline if statement.
|
||||
*/
|
||||
|
||||
if (bif == true && pnest == 0)
|
||||
{
|
||||
WARN("If statement followed by garbage", lineno, n);
|
||||
}
|
||||
|
||||
ERROR("Dangling whitespace at the end of line", lineno, m);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue