misra.py: Add R18.7 check#1934
Conversation
danmar
left a comment
There was a problem hiding this comment.
Thanks for looking at this!
| continue | ||
| structScopes.append(token.valueType.typeScope) | ||
|
|
||
| for scope in structScopes: |
There was a problem hiding this comment.
I suggest that you remove the structScopes above and change this loop:
for scope in data.scopes:
if scope.type != 'Struct':
continue
| token = scope.bodyStart.next | ||
| while token != scope.bodyEnd and token is not None: | ||
| # Handle nested structures to not duplicate an error. | ||
| if token.str == 'struct': |
There was a problem hiding this comment.
does this work?
if token.str == '{':
token = token.link
There was a problem hiding this comment.
Actually, no. I need a struct token to get its typeScope. This is necessary because I want to iterate over this scope ignoring possible nested structs like this:
struct {
struct {
struct {
uint8_t a3[42];
} s3;
} s2;
} s1;There was a problem hiding this comment.
yes with my code you would ignore all nested scopes.
| token = nestedStructScope.bodyEnd.next.next.next | ||
| continue | ||
|
|
||
| if token.str == '[' and token.next.str == ']': |
There was a problem hiding this comment.
hmm.. you can use cppcheckdata.simpleMatch(token, "[ ]")
| assert("(style)" in captured) | ||
|
|
||
|
|
||
| def test_misra_18_7(checker): |
There was a problem hiding this comment.
This is redundant .. Travis executes this command:
~/cppcheck/cppcheck --dump misra-test.c && python ../misra.py -verify misra-test.c.dump
And this command will verify that the addon outputs an error report on every marked line and nowhere else.
|
Thanks for the review. I corrected it. |
|
I checked out your code and changed it: This code works fine as far as I see. |
| return False | ||
|
|
||
|
|
||
| def isStruct(token): |
There was a problem hiding this comment.
the isStruct can be removed, I believe
|
Thanks! |
* misra.py: Add 18.7 check * Simplify R18.7 check * use token.link * Remove isStruct method
No description provided.