misc.py: Add check for implicitly virtual functions

This commit is contained in:
Daniel Marjamäki 2018-04-16 13:16:53 +02:00
parent a4f8c44432
commit d65f00fe2e
2 changed files with 22 additions and 5 deletions

View File

@ -32,9 +32,8 @@ def isStringLiteral(tokenString):
return tokenString.startswith('"')
# check data
def check(data):
def stringConcatInArrayInit(rawTokens):
arrayInit = False
rawTokens = data.rawTokens
for i in range(len(rawTokens)):
if i < 2:
continue
@ -54,7 +53,16 @@ def check(data):
continue
if i + 2 < len(rawTokens) and isStringLiteral(rawTokens[i+1].str) and isStringLiteral(rawTokens[i+2].str):
continue
reportError(rawTokens[i], 'style', 'string concatenation', 'stringConcatInArrayInit')
reportError(rawTokens[i], 'style', 'String concatenation in array initialization, missing comma?', 'stringConcatInArrayInit')
def implicitlyVirtual(data):
for cfg in data.configurations:
for function in cfg.functions:
if function.isImplicitlyVirtual is None:
continue
if not function.isImplicitlyVirtual:
continue
reportError(function.tokenDef, 'style', 'Function \'' + function.name + '\' overrides base class function but is not marked with \'virtual\' keyword.', 'implicitlyVirtual')
for arg in sys.argv[1:]:
if arg == '-verify':
@ -68,10 +76,11 @@ for arg in sys.argv[1:]:
for tok in data.rawTokens:
if tok.str.startswith('//'):
for word in tok.str[2:].split(' '):
if word == 'stringConcatInArrayInit':
if word == 'stringConcatInArrayInit' or word == 'implicitlyVirtual':
VERIFY_EXPECTED.append(str(tok.linenr) + ':' + word)
check(data)
stringConcatInArrayInit(data.rawTokens)
implicitlyVirtual(data)
if VERIFY:
for expected in VERIFY_EXPECTED:

View File

@ -16,3 +16,11 @@ const char *c[] = {
"b\n"
"b\n"
};
class base {
virtual void dostuff(int);
};
class derived : base {
void dostuff(int); // implicitlyVirtual
};