astyle FTW (should have read about that sooner)

This commit is contained in:
booga 2009-07-24 19:23:30 -04:00
parent 52e2e775b2
commit 9fa8c0ee9c
4 changed files with 49 additions and 48 deletions

View File

@ -1160,7 +1160,7 @@ void CheckOther::postIncrement()
if (decltok && Token::Match(decltok->previous(), "iterator|const_iterator"))
postIncrementError(tok2, tok2->strAt(1), (std::string("++") == tok2->strAt(2)));
// Is the variable a class?
else if (Token::findmatch( _tokenizer->tokens(), classDef.c_str() ))
else if (Token::findmatch(_tokenizer->tokens(), classDef.c_str()))
postIncrementError(tok2, tok2->strAt(1), (std::string("++") == tok2->strAt(2)));
break;
@ -1264,6 +1264,6 @@ void CheckOther::zerodivError(const Token *tok)
void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement)
{
std::string type = ( isIncrement ? "Incrementing" : "Decrementing" );
reportError(tok, Severity::possibleStyle, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type) );
std::string type = (isIncrement ? "Incrementing" : "Decrementing");
reportError(tok, Severity::possibleStyle, "postIncrementDecrement", ("Pre-" + type + " variable '" + var_name + "' is preferred to Post-" + type));
}

View File

@ -370,9 +370,9 @@ void CheckStl::stlBoundries()
{
// Declaring iterator..
const std::string checkStr = (std::string(STL_CONTAINER_LIST) + " <");
if (Token::Match( tok, checkStr.c_str() ))
if (Token::Match(tok, checkStr.c_str()))
{
const std::string container_name( tok->strAt(0) );
const std::string container_name(tok->strAt(0));
while (tok && tok->str() != ">")
tok = tok->next();
if (!tok)

View File

@ -639,43 +639,43 @@ private:
void postIncrementDecrementStl()
{
checkpostIncrementDecrement("void f1()\n"
"{\n"
" std::list<int>::iterator it;\n"
" for (it = ab.begin(); it != ab.end(); it++)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
checkpostIncrementDecrement("void f1()\n"
"{\n"
" std::list<int>::iterator it;\n"
" for (it = ab.begin(); it != ab.end(); it++)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
checkpostIncrementDecrement("void f2()\n"
"{\n"
" std::list<int>::iterator it;\n"
" for (it = ab.end(); it != ab.begin(); it--)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str());
checkpostIncrementDecrement("void f2()\n"
"{\n"
" std::list<int>::iterator it;\n"
" for (it = ab.end(); it != ab.begin(); it--)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str());
}
void postIncrementDecrementClass()
{
checkpostIncrementDecrement("class TestClass;\n"
"void f1()\n"
"{\n"
" TestClass tClass;\n"
" for (tClass = TestClass.begin(); tClass != TestClass.end(); tClass++)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Incrementing variable 'tClass' is preferred to Post-Incrementing\n", errout.str());
void postIncrementDecrementClass()
{
checkpostIncrementDecrement("class TestClass;\n"
"void f1()\n"
"{\n"
" TestClass tClass;\n"
" for (tClass = TestClass.begin(); tClass != TestClass.end(); tClass++)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Incrementing variable 'tClass' is preferred to Post-Incrementing\n", errout.str());
checkpostIncrementDecrement("class TestClass;\n"
"void f1()\n"
"{\n"
" TestClass tClass;\n"
" for (tClass = TestClass.end(); tClass != TestClass.begin(); tClass--)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str());
}
checkpostIncrementDecrement("class TestClass;\n"
"void f1()\n"
"{\n"
" TestClass tClass;\n"
" for (tClass = TestClass.end(); tClass != TestClass.begin(); tClass--)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (possible style) Pre-Decrementing variable 'tClass' is preferred to Post-Decrementing\n", errout.str());
}
};

View File

@ -377,19 +377,20 @@ private:
{
const int STL_CONTAINER_LIST = 10;
const std::string stlCont[STL_CONTAINER_LIST] =
{"vector", "deque", "list", "set", "multiset", "map",
"multimap", "hash_map", "hash_multimap", "hash_set"};
{"vector", "deque", "list", "set", "multiset", "map",
"multimap", "hash_map", "hash_multimap", "hash_set"
};
for(int i = 0; i < STL_CONTAINER_LIST; ++i)
for (int i = 0; i < STL_CONTAINER_LIST; ++i)
{
const std::string checkStr( "void f()\n"
"{\n"
" std::" + stlCont[i] + "<int>::iterator it;\n"
" for (it = ab.begin(); it < ab.end(); ++it)\n"
" ;\n"
"}\n" );
const std::string checkStr("void f()\n"
"{\n"
" std::" + stlCont[i] + "<int>::iterator it;\n"
" for (it = ab.begin(); it < ab.end(); ++it)\n"
" ;\n"
"}\n");
check( checkStr.c_str() );
check(checkStr.c_str());
ASSERT_EQUALS("[test.cpp:4]: (error) " + stlCont[i] + " range check should use != and not < since the order of the pointers isn't guaranteed\n", errout.str());
}