Another fix for handling of final/override specifiers in Tokenizer::simplifyKeyword() including a testcase. Ran astyle

This commit is contained in:
Alexander Mai 2015-05-23 20:51:15 +02:00
parent 355890375c
commit 7416d6add9
4 changed files with 46 additions and 23 deletions

View File

@ -3604,22 +3604,22 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n
bool SymbolDatabase::isReservedName(const std::string& iName) const
{
static const std::set<std::string> c_keywords = make_container<std::set<std::string>>() <<
"auto" << "break" << "case" << "char" << "const" << "continue" << "default" << "do" <<
"double" << "else" << "enum" << "extern" << "float" << "for" << "goto" << "if" << "inline" <<
"int" << "long" << "register" << "restrict" << "return" << "short" << "signed" << "sizeof" <<
"static" << "struct" << "switch" << "typedef" << "union" << "unsigned" << "void" << "volatile" <<
"while";
"auto" << "break" << "case" << "char" << "const" << "continue" << "default" << "do" <<
"double" << "else" << "enum" << "extern" << "float" << "for" << "goto" << "if" << "inline" <<
"int" << "long" << "register" << "restrict" << "return" << "short" << "signed" << "sizeof" <<
"static" << "struct" << "switch" << "typedef" << "union" << "unsigned" << "void" << "volatile" <<
"while";
static const std::set<std::string> cpp_keywords = make_container<std::set<std::string>>() <<
"alignas" << "alignof" << "and" << "and_eq" << "asm" << "auto" << "bitand" << "bitor" << "bool" <<
"break" << "case" << "catch" << "char" << "char16_t" << "char32_t" << "class" << "compl" <<
"concept" << "const" << "constexpr" << "const_cast" << "continue" << "decltype" << "default" <<
"delete" << "do" << "double" << "dynamic_cast" << "else" << "enum" << "explicit" << "export" <<
"extern" << "false" << "float" << "for" << "friend" << "goto" << "if" << "inline" << "int" << "long" <<
"mutable" << "namespace" << "new" << "noexcept" << "not" << "not_eq" << "nullptr" << "operator" <<
"or" << "or_eq" << "private" << "protected" << "public" << "register" << "reinterpret_cast" <<
"requires" << "return" << "short" << "signed" << "sizeof" << "static" << "static_assert" <<
"static_cast" << "struct" << "switch" << "template" << "this" << "thread_local" << "throw" <<
"true" << "try" << "typedef" << "typeid" << "typename" << "union" << "unsigned" << "using" <<
"virtual" << "void" << "volatile" << "wchar_t" << "while" << "xor" << "xor_eq";
"alignas" << "alignof" << "and" << "and_eq" << "asm" << "auto" << "bitand" << "bitor" << "bool" <<
"break" << "case" << "catch" << "char" << "char16_t" << "char32_t" << "class" << "compl" <<
"concept" << "const" << "constexpr" << "const_cast" << "continue" << "decltype" << "default" <<
"delete" << "do" << "double" << "dynamic_cast" << "else" << "enum" << "explicit" << "export" <<
"extern" << "false" << "float" << "for" << "friend" << "goto" << "if" << "inline" << "int" << "long" <<
"mutable" << "namespace" << "new" << "noexcept" << "not" << "not_eq" << "nullptr" << "operator" <<
"or" << "or_eq" << "private" << "protected" << "public" << "register" << "reinterpret_cast" <<
"requires" << "return" << "short" << "signed" << "sizeof" << "static" << "static_assert" <<
"static_cast" << "struct" << "switch" << "template" << "this" << "thread_local" << "throw" <<
"true" << "try" << "typedef" << "typeid" << "typename" << "union" << "unsigned" << "using" <<
"virtual" << "void" << "volatile" << "wchar_t" << "while" << "xor" << "xor_eq";
return (c_keywords.find(iName) != c_keywords.cend()) || (isCPP() && (cpp_keywords.find(iName) != cpp_keywords.cend()));
}

View File

@ -9308,7 +9308,7 @@ void Tokenizer::simplifyKeyword()
}
}
if (_settings->standards.cpp >= Standards::CPP11) {
if (isCPP() && _settings->standards.cpp >= Standards::CPP11) {
for (Token *tok = list.front(); tok; tok = tok->next()) {
while (tok->str() == "constexpr") {
tok->deleteThis();
@ -9327,12 +9327,17 @@ void Tokenizer::simplifyKeyword()
//if (Token::Match(tok, ") override [{;]"))
if (Token::Match(tok, ") const|override|final")) {
Token* specifier = tok->tokAt(2);
while (specifier && Token::Match(specifier, "const|override|final"))
while (specifier && Token::Match(specifier, "const|override|final")) {
specifier=specifier->next();
}
if (specifier && Token::Match(specifier, "[{;]")) {
specifier=tok->next();
while (specifier->str()=="override" || specifier->str()=="final")
specifier->deleteThis();
specifier = tok->next();
while (!Token::Match(specifier, "[{;]")) {
if (specifier->str()=="const")
specifier=specifier->next();
else
specifier->deleteThis();
}
}
}
}

View File

@ -1195,7 +1195,7 @@ private:
" HeapDestroy(MyHeap);"
"}");
TODO_ASSERT_EQUALS("", "[test.c:1]: (error) Mismatching allocation and deallocation: MyHeap\n"
"[test.c:1]: (error) Resource handle 'MyHeap' freed twice.\n", errout.str());
"[test.c:1]: (error) Resource handle 'MyHeap' freed twice.\n", errout.str());
check("void f() {"
" int *a = HeapAlloc(GetProcessHeap(), 0, sizeof(int));"
@ -1213,7 +1213,7 @@ private:
" HeapDestroy(MyHeap);"
"}");
TODO_ASSERT_EQUALS("[test.c:1] (error) Memory leak: b", "[test.c:1]: (error) Mismatching allocation and deallocation: MyHeap\n"
"[test.c:1]: (error) Memory leak: b\n", errout.str());
"[test.c:1]: (error) Memory leak: b\n", errout.str());
check("void f() {"
" HANDLE MyHeap = HeapCreate(0, 0, 0);"

View File

@ -4485,6 +4485,24 @@ private:
const char in4 [] = "struct B final : A { void foo(); };";
const char out4 [] = "struct B : A { void foo ( ) ; } ;";
ASSERT_EQUALS(out4, tokenizeAndStringify(in4));
const char in5 [] = "struct ArrayItemsValidator final {\n"
" SchemaError validate() const override {\n"
" for (; pos < value.size(); ++pos) {\n"
" }\n"
" return none;\n"
" }\n"
"};\n";
const char out5 [] =
"struct ArrayItemsValidator {\n"
"SchemaError validate ( ) const {\n"
"for ( ; pos < value . size ( ) ; ++ pos ) {\n"
"}\n"
"return none ;\n"
"}\n"
"} ;";
ASSERT_EQUALS(out5, tokenizeAndStringify(in5));
}
}