misra: fix void parameter check
This commit is contained in:
parent
4bf8718dcb
commit
ea63b8e2bb
|
@ -202,6 +202,7 @@ class Token:
|
||||||
isUnsigned Is this token a unsigned type
|
isUnsigned Is this token a unsigned type
|
||||||
isSigned Is this token a signed type
|
isSigned Is this token a signed type
|
||||||
isExpandedMacro Is this token a expanded macro token
|
isExpandedMacro Is this token a expanded macro token
|
||||||
|
isRemovedVoidParameter Has void parameter been removed?
|
||||||
isSplittedVarDeclComma Is this a comma changed to semicolon in a splitted variable declaration ('int a,b;' => 'int a; int b;')
|
isSplittedVarDeclComma Is this a comma changed to semicolon in a splitted variable declaration ('int a,b;' => 'int a; int b;')
|
||||||
isSplittedVarDeclEq Is this a '=' changed to semicolon in a splitted variable declaration ('int a=5;' => 'int a; a=5;')
|
isSplittedVarDeclEq Is this a '=' changed to semicolon in a splitted variable declaration ('int a=5;' => 'int a; a=5;')
|
||||||
isImplicitInt Is this token an implicit "int"?
|
isImplicitInt Is this token an implicit "int"?
|
||||||
|
@ -254,6 +255,7 @@ class Token:
|
||||||
isUnsigned = False
|
isUnsigned = False
|
||||||
isSigned = False
|
isSigned = False
|
||||||
isExpandedMacro = False
|
isExpandedMacro = False
|
||||||
|
isRemovedVoidParameter = False
|
||||||
isSplittedVarDeclComma = False
|
isSplittedVarDeclComma = False
|
||||||
isSplittedVarDeclEq = False
|
isSplittedVarDeclEq = False
|
||||||
isImplicitInt = False
|
isImplicitInt = False
|
||||||
|
@ -318,6 +320,8 @@ class Token:
|
||||||
self.isLogicalOp = True
|
self.isLogicalOp = True
|
||||||
if element.get('isExpandedMacro'):
|
if element.get('isExpandedMacro'):
|
||||||
self.isExpandedMacro = True
|
self.isExpandedMacro = True
|
||||||
|
if element.get('isRemovedVoidParameter'):
|
||||||
|
self.isRemovedVoidParameter = True
|
||||||
if element.get('isSplittedVarDeclComma'):
|
if element.get('isSplittedVarDeclComma'):
|
||||||
self.isSplittedVarDeclComma = True
|
self.isSplittedVarDeclComma = True
|
||||||
if element.get('isSplittedVarDeclEq'):
|
if element.get('isSplittedVarDeclEq'):
|
||||||
|
|
|
@ -1863,19 +1863,12 @@ class MisraChecker:
|
||||||
return following
|
return following
|
||||||
|
|
||||||
# Zero arguments should be in form ( void )
|
# Zero arguments should be in form ( void )
|
||||||
# TODO: Use rawTokens or add flag when void is removed
|
|
||||||
def checkZeroArguments(func, startCall, endCall):
|
def checkZeroArguments(func, startCall, endCall):
|
||||||
if (len(func.argument) == 0):
|
if not startCall.isRemovedVoidParameter and len(func.argument) == 0:
|
||||||
voidArg = startCall.next
|
if func.tokenDef.next:
|
||||||
while voidArg is not endCall:
|
self.reportError(func.tokenDef.next, 8, 2)
|
||||||
if voidArg.str == 'void':
|
else:
|
||||||
break
|
self.reportError(func.tokenDef, 8, 2)
|
||||||
voidArg = voidArg.next
|
|
||||||
if not voidArg.str == 'void':
|
|
||||||
if func.tokenDef.next:
|
|
||||||
self.reportError(func.tokenDef.next, 8, 2)
|
|
||||||
else:
|
|
||||||
self.reportError(func.tokenDef, 8, 2)
|
|
||||||
|
|
||||||
def checkDeclarationArgumentsViolations(func, startCall, endCall):
|
def checkDeclarationArgumentsViolations(func, startCall, endCall):
|
||||||
# Collect the tokens for the arguments in function definition
|
# Collect the tokens for the arguments in function definition
|
||||||
|
@ -1936,7 +1929,7 @@ class MisraChecker:
|
||||||
endCall = startCall.link
|
endCall = startCall.link
|
||||||
if endCall is None or endCall.str != ')':
|
if endCall is None or endCall.str != ')':
|
||||||
continue
|
continue
|
||||||
# checkZeroArguments(func, startCall, endCall)
|
checkZeroArguments(func, startCall, endCall)
|
||||||
checkDefinitionArgumentsViolations(func, startCall, endCall)
|
checkDefinitionArgumentsViolations(func, startCall, endCall)
|
||||||
|
|
||||||
# Check arguments in function declaration
|
# Check arguments in function declaration
|
||||||
|
@ -1948,7 +1941,7 @@ class MisraChecker:
|
||||||
endCall = startCall.link
|
endCall = startCall.link
|
||||||
if endCall is None or endCall.str != ')':
|
if endCall is None or endCall.str != ')':
|
||||||
continue
|
continue
|
||||||
# checkZeroArguments(func, startCall, endCall)
|
checkZeroArguments(func, startCall, endCall)
|
||||||
if tokenImpl:
|
if tokenImpl:
|
||||||
checkDeclarationArgumentsViolations(func, startCall, endCall)
|
checkDeclarationArgumentsViolations(func, startCall, endCall)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -337,7 +337,7 @@ const misra_8_1_a; // 8.1 8.4
|
||||||
static int misra_8_2_a (int n, ...);
|
static int misra_8_2_a (int n, ...);
|
||||||
extern int misra_8_2_b (int n);
|
extern int misra_8_2_b (int n);
|
||||||
extern int misra_8_2_c (int); // 8.2
|
extern int misra_8_2_c (int); // 8.2
|
||||||
static int misra_8_2_d (); // TODO: 8.2
|
static int misra_8_2_d (); // 8.2
|
||||||
static int misra_8_2_e (void);
|
static int misra_8_2_e (void);
|
||||||
static int misra_8_2_f (vec, n )
|
static int misra_8_2_f (vec, n )
|
||||||
int *vec; // 8.2
|
int *vec; // 8.2
|
||||||
|
@ -345,13 +345,13 @@ int n; // 8.2
|
||||||
{
|
{
|
||||||
return vec[ n - 1 ];
|
return vec[ n - 1 ];
|
||||||
}
|
}
|
||||||
static int misra_8_2_g ( /* comment */ ); // TODO: 8.2
|
static int misra_8_2_g ( /* comment */ ); // 8.2
|
||||||
static int misra_8_2_h ( /* comment 1 */ /* comment 2 */ ); // TODO: 8.2
|
static int misra_8_2_h ( /* comment 1 */ /* comment 2 */ ); // 8.2
|
||||||
static int misra_8_2_i ( /* comment */ void);
|
static int misra_8_2_i ( /* comment */ void);
|
||||||
static int misra_8_2_j ( /* comment */ void /* comment */);
|
static int misra_8_2_j ( /* comment */ void /* comment */);
|
||||||
static int misra_8_2_k ( //
|
static int misra_8_2_k ( //
|
||||||
void);
|
void);
|
||||||
static int misra_8_2_l ( // TODO: 8.2
|
static int misra_8_2_l ( // 8.2
|
||||||
);
|
);
|
||||||
static void misra_8_2_m(uint8_t * const x);
|
static void misra_8_2_m(uint8_t * const x);
|
||||||
static void misra_8_2_m(uint8_t * const x)
|
static void misra_8_2_m(uint8_t * const x)
|
||||||
|
@ -373,7 +373,7 @@ static int misra_8_2_p(
|
||||||
const uint8_t *const a2
|
const uint8_t *const a2
|
||||||
);
|
);
|
||||||
static int misra_8_2_q
|
static int misra_8_2_q
|
||||||
(); // TODO: 8.2
|
(); // 8.2
|
||||||
|
|
||||||
void misra_8_4_foo(void) {} // 8.4
|
void misra_8_4_foo(void) {} // 8.4
|
||||||
extern void misra_8_4_func(void);
|
extern void misra_8_4_func(void);
|
||||||
|
|
|
@ -644,6 +644,13 @@ public:
|
||||||
setFlag(fIsInline, b);
|
setFlag(fIsInline, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isRemovedVoidParameter() const {
|
||||||
|
return getFlag(fIsRemovedVoidParameter);
|
||||||
|
}
|
||||||
|
void setRemovedVoidParameter(bool b) {
|
||||||
|
setFlag(fIsRemovedVoidParameter, b);
|
||||||
|
}
|
||||||
|
|
||||||
bool isTemplate() const {
|
bool isTemplate() const {
|
||||||
return getFlag(fIsTemplate);
|
return getFlag(fIsTemplate);
|
||||||
}
|
}
|
||||||
|
@ -1263,6 +1270,7 @@ private:
|
||||||
fIsInline = (1ULL << 32), // Is this a inline type
|
fIsInline = (1ULL << 32), // Is this a inline type
|
||||||
fIsTemplate = (1ULL << 33),
|
fIsTemplate = (1ULL << 33),
|
||||||
fIsSimplifedScope = (1ULL << 34), // scope added when simplifying e.g. if (int i = ...; ...)
|
fIsSimplifedScope = (1ULL << 34), // scope added when simplifying e.g. if (int i = ...; ...)
|
||||||
|
fIsRemovedVoidParameter = (1ULL << 35), // A void function parameter has been removed
|
||||||
};
|
};
|
||||||
|
|
||||||
Token::Type mTokType;
|
Token::Type mTokType;
|
||||||
|
|
|
@ -3111,10 +3111,10 @@ void Tokenizer::simplifyArrayAccessSyntax()
|
||||||
void Tokenizer::simplifyParameterVoid()
|
void Tokenizer::simplifyParameterVoid()
|
||||||
{
|
{
|
||||||
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "sizeof|decltype|typeof"))
|
if (Token::Match(tok, "%name% ( void )") && !Token::Match(tok, "sizeof|decltype|typeof")) {
|
||||||
continue;
|
|
||||||
if (Token::Match(tok, "%name% ( void )"))
|
|
||||||
tok->next()->deleteNext();
|
tok->next()->deleteNext();
|
||||||
|
tok->next()->setRemovedVoidParameter(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5544,6 +5544,8 @@ void Tokenizer::dump(std::ostream &out) const
|
||||||
}
|
}
|
||||||
if (tok->isExpandedMacro())
|
if (tok->isExpandedMacro())
|
||||||
out << " isExpandedMacro=\"true\"";
|
out << " isExpandedMacro=\"true\"";
|
||||||
|
if (tok->isRemovedVoidParameter())
|
||||||
|
out << " isRemovedVoidParameter=\"true\"";
|
||||||
if (tok->isSplittedVarDeclComma())
|
if (tok->isSplittedVarDeclComma())
|
||||||
out << " isSplittedVarDeclComma=\"true\"";
|
out << " isSplittedVarDeclComma=\"true\"";
|
||||||
if (tok->isSplittedVarDeclEq())
|
if (tok->isSplittedVarDeclEq())
|
||||||
|
|
Loading…
Reference in New Issue