You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/03/09 16:00:34 UTC
[incubator-nuttx] branch master updated (9e40a0d -> f764947)
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.
from 9e40a0d sched/semaphore/sem_holder.c: Fix bad line separation.
new 574344c Changes to nxstyle which address issue #120 and add checks for column position of right of code comments
new b324596 Formatting
new 46b8347 Style
new fbe65a2 Restrict check of right of code comments to #define in case of preprocessor lines
new 5e5b6c2 Finetuning false positive
new 745e0a4 Some more fine tuning Handle #define different than other preprocessor lines Ignore backslash at the end of a comment right of a preprocessor line
new f764947 Signal error for multiline comment right of #if
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
tools/nxstyle.c | 174 +++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 115 insertions(+), 59 deletions(-)
[incubator-nuttx] 04/07: Restrict check of right of code comments
to #define in case of preprocessor lines
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit fbe65a2d7dc5024e829ceba1409f9da8c0c68d76
Author: Johanne Schock <jo...@nivus.com>
AuthorDate: Sun Mar 8 22:24:27 2020 +0100
Restrict check of right of code comments to #define in case of preprocessor lines
---
tools/nxstyle.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 47c5615..9edd48f 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -941,12 +941,15 @@ int main(int argc, char **argv, char **envp)
ncomment++;
}
- rhcomment = n;
- if (prevrhcmt != 0 && n != prevrhcmt)
+ if (!strncmp(&line[ii], "define", 6))
{
- rhcomment = prevrhcmt;
- WARN("Wrong column position of comment right of code",
- lineno, n);
+ rhcomment = n;
+ if (prevrhcmt != 0 && n != prevrhcmt)
+ {
+ rhcomment = prevrhcmt;
+ WARN("Wrong column position of comment right of code",
+ lineno, n);
+ }
}
}
}
[incubator-nuttx] 06/07: Some more fine tuning Handle #define
different than other preprocessor lines Ignore backslash at the end of a
comment right of a preprocessor line
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 745e0a4ca9de577405a8ab2a6a4294b3225e4ef3
Author: Johanne Schock <jo...@nivus.com>
AuthorDate: Mon Mar 9 12:53:21 2020 +0100
Some more fine tuning
Handle #define different than other preprocessor lines
Ignore backslash at the end of a comment right of a preprocessor line
---
tools/nxstyle.c | 121 +++++++++++++++++++++++++++++++++-----------------------
1 file changed, 72 insertions(+), 49 deletions(-)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index d704df3..71ca4c2 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -112,6 +112,13 @@ enum section_s
PUBLIC_FUNCTION_PROTOTYPES
};
+enum pptype_e
+{
+ PPLINE_NONE = 0,
+ PPLINE_DEFINE,
+ PPLINE_OTHER
+};
+
struct file_section_s
{
const char *name; /* File section name */
@@ -503,10 +510,13 @@ int main(int argc, char **argv, char **envp)
bool bstring; /* True: Within a string */
bool bquote; /* True: Backslash quoted character next */
bool bblank; /* Used to verify block comment terminator */
- bool ppline; /* True: The next line the continuation of a pre-processor command */
bool bexternc; /* True: Within 'extern "C"' */
- int rhcomment; /* Indentation of Comment to the right of code */
- int prevrhcmt; /* Indentation of previous Comment to the right of code */
+ enum pptype_e ppline; /* > 0: The next line the continuation of a
+ * pre-processor command */
+ int rhcomment; /* Indentation of Comment to the right of code
+ * (-1 -> don't check position) */
+ int prevrhcmt; /* Indentation of previous Comment to the right
+ * of code (-1 -> don't check position) */
int lineno; /* Current line number */
int indent; /* Indentation level */
int ncomment; /* Comment nesting level on this line */
@@ -618,27 +628,29 @@ int main(int argc, char **argv, char **envp)
g_maxline = get_line_width(instream) + excess;
rewind(instream);
- btabs = false; /* True: TAB characters found on the line */
- bcrs = false; /* True: Carriage return found on the line */
- bfunctions = false; /* True: In private or public functions */
- bswitch = false; /* True: Within a switch statement */
- bstring = false; /* True: Within a string */
- ppline = false; /* True: Continuation of a pre-processor line */
- bexternc = false; /* True: Within 'extern "C"' */
- rhcomment = 0; /* Indentation of Comment to the right of code */
- prevrhcmt = 0; /* Indentation of previous Comment to the right
- * of code */
- lineno = 0; /* Current line number */
- ncomment = 0; /* Comment nesting level on this line */
- bnest = 0; /* Brace nesting level on this line */
- dnest = 0; /* Data declaration nesting level on this line */
- pnest = 0; /* Parenthesis nesting level on this line */
- comment_lineno = -1; /* Line on which the last comment was closed */
- blank_lineno = -1; /* Line number of the last blank line */
- noblank_lineno = -1; /* A blank line is not needed after this line */
- lbrace_lineno = -1; /* Line number of last left brace */
- rbrace_lineno = -1; /* Last line containing a right brace */
- externc_lineno = -1; /* Last line where 'extern "C"' declared */
+ btabs = false; /* True: TAB characters found on the line */
+ bcrs = false; /* True: Carriage return found on the line */
+ bfunctions = false; /* True: In private or public functions */
+ bswitch = false; /* True: Within a switch statement */
+ bstring = false; /* True: Within a string */
+ bexternc = false; /* True: Within 'extern "C"' */
+ ppline = PPLINE_NONE; /* > 0: The next line the continuation of a
+ * pre-processor command */
+ rhcomment = 0; /* Indentation of Comment to the right of code
+ * (-1 -> don't check position) */
+ prevrhcmt = 0; /* Indentation of previous Comment to the right
+ * of code (-1 -> don't check position) */
+ lineno = 0; /* Current line number */
+ ncomment = 0; /* Comment nesting level on this line */
+ bnest = 0; /* Brace nesting level on this line */
+ dnest = 0; /* Data declaration nesting level on this line */
+ pnest = 0; /* Parenthesis nesting level on this line */
+ comment_lineno = -1; /* Line on which the last comment was closed */
+ blank_lineno = -1; /* Line number of the last blank line */
+ noblank_lineno = -1; /* A blank line is not needed after this line */
+ lbrace_lineno = -1; /* Line number of last left brace */
+ rbrace_lineno = -1; /* Last line containing a right brace */
+ externc_lineno = -1; /* Last line where 'extern "C"' declared */
/* Process each line in the input stream */
@@ -827,7 +839,7 @@ int main(int argc, char **argv, char **envp)
* lines as indicated by ppline)
*/
- if (line[indent] == '#' || ppline)
+ if (line[indent] == '#' || ppline != PPLINE_NONE)
{
int len;
int ii;
@@ -840,7 +852,7 @@ int main(int argc, char **argv, char **envp)
* line.
*/
- if (!ppline)
+ if (ppline == PPLINE_NONE)
{
/* Skip to the pre-processor command following the '#' */
@@ -856,8 +868,12 @@ int main(int argc, char **argv, char **envp)
* the pre-processor definitions section.
*/
+ ppline = PPLINE_OTHER;
+
if (strncmp(&line[ii], "define", 6) == 0)
{
+ ppline = PPLINE_DEFINE;
+
if (g_section != PRE_PROCESSOR_DEFINITIONS)
{
/* A complication is the header files always have
@@ -913,44 +929,51 @@ int main(int argc, char **argv, char **envp)
len--;
}
- ppline = (line[len] == '\\');
-
/* Propagate rhcomment over preprocessor lines Issue #120 */
rhcomment = prevrhcmt;
- if (!ppline)
+ lptr = strstr(line, "/*");
+ if (lptr != NULL)
{
- lptr = strstr(line, "/*");
- if (lptr != NULL)
+ n = lptr - &line[0];
+ if (line[n + 2] == '\n')
{
- n = lptr - &line[0];
- if (line[n + 2] == '\n')
- {
- ERROR("C comment opening on separate line", lineno, n);
- }
- else if (!isspace((int)line[n + 2]) && line[n + 2] != '*')
- {
- ERROR("Missing space after opening C comment", lineno, n);
- }
+ ERROR("C comment opening on separate line", lineno, n);
+ }
+ else if (!isspace((int)line[n + 2]) && line[n + 2] != '*')
+ {
+ ERROR("Missing space after opening C comment", lineno, n);
+ }
- if (strstr(lptr, "*/") == NULL)
- {
- /* Increment the count of nested comments */
+ if (strstr(lptr, "*/") == NULL)
+ {
+ /* Increment the count of nested comments */
- ncomment++;
- }
+ ncomment++;
+ }
+ if (ppline == PPLINE_DEFINE)
+ {
rhcomment = n;
-
- if (!strncmp(&line[ii], "define", 6)
- && prevrhcmt != 0 && n != prevrhcmt)
+ if (prevrhcmt > 0 && n != prevrhcmt)
{
rhcomment = prevrhcmt;
WARN("Wrong column position of comment right of code",
lineno, n);
}
}
+ else
+ {
+ /* Signal rhcomment, but ignore position */
+
+ rhcomment = -1;
+ }
+ }
+
+ if (line[len] != '\\' || ncomment > 0)
+ {
+ ppline = PPLINE_NONE;
}
continue;
@@ -1413,7 +1436,7 @@ int main(int argc, char **argv, char **envp)
else
{
rhcomment = n;
- if (n != prevrhcmt)
+ if (prevrhcmt > 0 && n != prevrhcmt)
{
rhcomment = prevrhcmt;
WARN("Wrong column position of comment right of code",
[incubator-nuttx] 01/07: Changes to nxstyle which address issue
#120 and add checks for column position of right of code comments
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 574344c56eabd2117f1128c165420a09bd1e245f
Author: Johanne Schock <jo...@nivus.com>
AuthorDate: Sun Mar 8 20:02:51 2020 +0100
Changes to nxstyle which address issue #120 and add checks for column position of right of code comments
---
tools/nxstyle.c | 79 +++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 52 insertions(+), 27 deletions(-)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index f49c84f..2ef78dd 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -505,8 +505,8 @@ int main(int argc, char **argv, char **envp)
bool bblank; /* Used to verify block comment terminator */
bool ppline; /* True: The next line the continuation of a pre-processor command */
bool bexternc; /* True: Within 'extern "C"' */
- bool brhcomment; /* True: Comment to the right of code */
- bool prevbrhcmt; /* True: previous line had comment to the right of code */
+ int rhcomment; /* Indentation of Comment to the right of code */
+ int prevrhcmt; /* Indentation of previous Comment to the right of code */
int lineno; /* Current line number */
int indent; /* Indentation level */
int ncomment; /* Comment nesting level on this line */
@@ -625,8 +625,8 @@ int main(int argc, char **argv, char **envp)
bstring = false; /* True: Within a string */
ppline = false; /* True: Continuation of a pre-processor line */
bexternc = false; /* True: Within 'extern "C"' */
- brhcomment = false; /* True: Comment to the right of code */
- prevbrhcmt = false; /* True: Previous line had comment to the right
+ rhcomment = 0; /* Indentation of Comment to the right of code */
+ prevrhcmt = 0; /* Indentation of previous Comment to the right
* of code */
lineno = 0; /* Current line number */
ncomment = 0; /* Comment nesting level on this line */
@@ -658,10 +658,10 @@ int main(int argc, char **argv, char **envp)
* comment.
*/
- prevbrhcmt = brhcomment;
+ prevrhcmt = rhcomment;
if (ncomment <= 0)
{
- brhcomment = false;
+ rhcomment = 0;
}
/* Check for a blank line */
@@ -707,7 +707,7 @@ int main(int argc, char **argv, char **envp)
* a comment. Generally it is acceptable for one comment to
* follow another with no space separation.
*
- * REVISIT: prevbrhcmt is tested to case the preceding line
+ * REVISIT: prevrhcmt is tested to case the preceding line
* contained comments to the right of the code. In such cases,
* the comments are normally aligned and do not follow normal
* indentation rules. However, this code will generate a false
@@ -715,7 +715,7 @@ int main(int argc, char **argv, char **envp)
* preceding line has no comment.
*/
- if (line[n] != '}' && line[n] != '#' && !prevbrhcmt)
+ if (line[n] != '}' && line[n] != '#' && !prevrhcmt)
{
ERROR("Missing blank line after comment", comment_lineno,
1);
@@ -915,21 +915,23 @@ int main(int argc, char **argv, char **envp)
ppline = (line[len] == '\\');
+ /* Propagate rhcomment over preprocessor lines Issue #120 */
+
+ rhcomment = prevrhcmt;
+
if (!ppline)
{
lptr = strstr(line, "/*");
if (lptr != NULL)
{
- lptr += 2;
- if (*lptr == '\n')
+ n = lptr - &line[0];
+ if (line[n + 2] == '\n')
{
- ERROR("C comment opening on separate line",
- lineno, lptr - &line[0]);
+ ERROR("C comment opening on separate line", lineno, n);
}
- else if (!isspace((int)*lptr))
+ else if (!isspace((int)line[n + 2]) && line[n + 2] != '*')
{
- ERROR("Missing space after opening C comment",
- lineno, lptr - &line[0]);
+ ERROR("Missing space after opening C comment", lineno, n);
}
if (strstr(lptr, "*/") == NULL)
@@ -937,7 +939,14 @@ int main(int argc, char **argv, char **envp)
/* Increment the count of nested comments */
ncomment++;
- brhcomment = true;
+ }
+
+ rhcomment = n;
+ if (prevrhcmt != 0 && n != prevrhcmt)
+ {
+ rhcomment = prevrhcmt;
+ WARN("Wrong column position of comment right of code",
+ lineno, n);
}
}
}
@@ -956,11 +965,11 @@ int main(int argc, char **argv, char **envp)
{
/* If preceding comments were to the right of code, then we can
* assume that there is a columnar alignment of columns that do
- * no follow the usual alignment. So the brhcomment flag
+ * no follow the usual alignment. So the rhcomment flag
* should propagate.
*/
- brhcomment = prevbrhcmt;
+ rhcomment = prevrhcmt;
/* Check if there should be a blank line before the comment */
@@ -968,7 +977,7 @@ int main(int argc, char **argv, char **envp)
comment_lineno != lineno - 1 &&
blank_lineno != lineno - 1 &&
noblank_lineno != lineno - 1 &&
- !brhcomment)
+ rhcomment == 0)
{
/* TODO: This generates a false alarm if preceded
* by a label.
@@ -1388,11 +1397,27 @@ int main(int argc, char **argv, char **envp)
* this must be a comment to the right of code.
* Also if preceding comments were to the right of code, then
* we can assume that there is a columnar alignment of columns
- * that do no follow the usual alignment. So the brhcomment
+ * that do no follow the usual alignment. So the rhcomment
* flag should propagate.
*/
- brhcomment = ((n != indent) || prevbrhcmt);
+ if (prevrhcmt == 0)
+ {
+ if (n != indent)
+ {
+ rhcomment = n;
+ }
+ }
+ else
+ {
+ rhcomment = n;
+ if (n != prevrhcmt)
+ {
+ rhcomment = prevrhcmt;
+ WARN("Wrong column position of comment right of code",
+ lineno, n);
+ }
+ }
n++;
continue;
@@ -1418,7 +1443,7 @@ int main(int argc, char **argv, char **envp)
* not blank up to the point where the comment was closed.
*/
- if (prevncomment > 0 && !bblank && !brhcomment)
+ if (prevncomment > 0 && !bblank && rhcomment == 0)
{
ERROR("Block comment terminator must be on a "
"separate line", lineno, n);
@@ -1453,7 +1478,7 @@ int main(int argc, char **argv, char **envp)
comment_lineno = lineno;
- /* Note that brhcomment must persist to support a
+ /* Note that rhcomment must persist to support a
* later test for comment alignment. We will fix
* that at the top of the loop when ncomment == 0.
*/
@@ -1461,7 +1486,7 @@ int main(int argc, char **argv, char **envp)
}
else
{
- /* Note that brhcomment must persist to support a later
+ /* Note that rhcomment must persist to support a later
* test for comment alignment. We will will fix that
* at the top of the loop when ncomment == 0.
*/
@@ -2211,7 +2236,7 @@ int main(int argc, char **argv, char **envp)
* already incremented above.
*/
- if (ncomment > 1 || !brhcomment)
+ if (ncomment > 1 || rhcomment == 0)
{
ERROR("No indentation line", lineno, indent);
}
@@ -2244,7 +2269,7 @@ int main(int argc, char **argv, char **envp)
* aligned to the right of the code.
*/
- if ((indent & 3) != 2 && !brhcomment)
+ if ((indent & 3) != 2 && rhcomment == 0)
{
ERROR("Bad comment alignment", lineno, indent);
}
@@ -2271,7 +2296,7 @@ int main(int argc, char **argv, char **envp)
*/
if ((indent & 3) != 3 && bfunctions && dnest == 0 &&
- !brhcomment)
+ rhcomment == 0)
{
ERROR("Bad comment block alignment", lineno, indent);
}
[incubator-nuttx] 07/07: Signal error for multiline comment right
of #if
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit f764947c731fbc65d33aceb4da3e25513a2013c6
Author: Johanne Schock <jo...@nivus.com>
AuthorDate: Mon Mar 9 16:16:06 2020 +0100
Signal error for multiline comment right of #if
---
tools/nxstyle.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 71ca4c2..9b7badd 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -968,6 +968,12 @@ int main(int argc, char **argv, char **envp)
/* Signal rhcomment, but ignore position */
rhcomment = -1;
+
+ if (ncomment > 0 && !strncmp(&line[ii], "if", 2))
+ {
+ ERROR("No multiline comment right of code allowed here",
+ lineno, n);
+ }
}
}
[incubator-nuttx] 05/07: Finetuning false positive
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 5e5b6c206993815f8bf11598825e22ca6e726517
Author: Johanne Schock <jo...@nivus.com>
AuthorDate: Sun Mar 8 22:37:39 2020 +0100
Finetuning false positive
---
tools/nxstyle.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 9edd48f..d704df3 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -941,15 +941,14 @@ int main(int argc, char **argv, char **envp)
ncomment++;
}
- if (!strncmp(&line[ii], "define", 6))
+ rhcomment = n;
+
+ if (!strncmp(&line[ii], "define", 6)
+ && prevrhcmt != 0 && n != prevrhcmt)
{
- rhcomment = n;
- if (prevrhcmt != 0 && n != prevrhcmt)
- {
- rhcomment = prevrhcmt;
- WARN("Wrong column position of comment right of code",
- lineno, n);
- }
+ rhcomment = prevrhcmt;
+ WARN("Wrong column position of comment right of code",
+ lineno, n);
}
}
}
[incubator-nuttx] 02/07: Formatting
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit b324596bac6eb3cc00cdf3aa034d13be42e8a4d7
Author: Johanne Schock <jo...@nivus.com>
AuthorDate: Sun Mar 8 20:08:47 2020 +0100
Formatting
---
tools/nxstyle.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 2ef78dd..cf3a378 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -505,8 +505,8 @@ int main(int argc, char **argv, char **envp)
bool bblank; /* Used to verify block comment terminator */
bool ppline; /* True: The next line the continuation of a pre-processor command */
bool bexternc; /* True: Within 'extern "C"' */
- int rhcomment; /* Indentation of Comment to the right of code */
- int prevrhcmt; /* Indentation of previous Comment to the right of code */
+ int rhcomment; /* Indentation of Comment to the right of code */
+ int prevrhcmt; /* Indentation of previous Comment to the right of code */
int lineno; /* Current line number */
int indent; /* Indentation level */
int ncomment; /* Comment nesting level on this line */
@@ -625,8 +625,8 @@ int main(int argc, char **argv, char **envp)
bstring = false; /* True: Within a string */
ppline = false; /* True: Continuation of a pre-processor line */
bexternc = false; /* True: Within 'extern "C"' */
- rhcomment = 0; /* Indentation of Comment to the right of code */
- prevrhcmt = 0; /* Indentation of previous Comment to the right
+ rhcomment = 0; /* Indentation of Comment to the right of code */
+ prevrhcmt = 0; /* Indentation of previous Comment to the right
* of code */
lineno = 0; /* Current line number */
ncomment = 0; /* Comment nesting level on this line */
@@ -658,7 +658,7 @@ int main(int argc, char **argv, char **envp)
* comment.
*/
- prevrhcmt = rhcomment;
+ prevrhcmt = rhcomment;
if (ncomment <= 0)
{
rhcomment = 0;
[incubator-nuttx] 03/07: Style
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 46b8347217f5ab3cd8b08bb4dfbfbbf415321e5b
Author: Johanne Schock <jo...@nivus.com>
AuthorDate: Sun Mar 8 20:12:06 2020 +0100
Style
---
tools/nxstyle.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index cf3a378..47c5615 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -715,7 +715,7 @@ int main(int argc, char **argv, char **envp)
* preceding line has no comment.
*/
- if (line[n] != '}' && line[n] != '#' && !prevrhcmt)
+ if (line[n] != '}' && line[n] != '#' && prevrhcmt == 0)
{
ERROR("Missing blank line after comment", comment_lineno,
1);