Moved Tokenizer::typeConstToConstType() to Tokenizer::simplifyConst()

This commit is contained in:
PKEuS 2012-09-07 11:41:41 +02:00
parent 9a375744a4
commit 489df29346
3 changed files with 15 additions and 35 deletions

View File

@ -1947,9 +1947,6 @@ bool Tokenizer::tokenize(std::istream &code,
tok = fortok;
}*/
// Convert "type const" to "const type"
typeConstToConstType();
simplifyConst();
// struct simplification "struct S {} s; => struct S { } ; S s ;
@ -8084,27 +8081,20 @@ void Tokenizer::simplifyComparisonOrder()
}
}
void Tokenizer::typeConstToConstType()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->isStandardType() && Token::simpleMatch(tok->next(), "const")) {
tok->next()->str(tok->str());
tok->str("const");
} else if (Token::Match(tok, "struct %type% const")) {
tok->next()->next()->str(tok->next()->str());
tok->str("const");
tok->next()->str("struct");
}
}
}
void Tokenizer::simplifyConst()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "%type% const") &&
(!tok->previous() || Token::Match(tok->previous(), "[;{}(,]")) &&
tok->str().find(":") == std::string::npos &&
tok->str() != "operator") {
if (tok->isStandardType() && tok->strAt(1) == "const") {
tok->next()->str(tok->str());
tok->str("const");
} else if (Token::Match(tok, "struct %type% const")) {
tok->tokAt(2)->str(tok->next()->str());
tok->str("const");
tok->next()->str("struct");
} else if (Token::Match(tok, "%type% const") &&
(!tok->previous() || Token::Match(tok->previous(), "[;{}(,]")) &&
tok->str().find(":") == std::string::npos &&
tok->str() != "operator") {
tok->next()->str(tok->str());
tok->str("const");
}

View File

@ -480,12 +480,6 @@ public:
*/
void simplifyComparisonOrder();
/**
* simplify "type const" to "const type"
* For example: int const x => const int x
*/
void typeConstToConstType();
/**
* Change "int const x;" into "const int x;"
*/

View File

@ -57,8 +57,6 @@ private:
TEST_CASE(tokenize22); // special marker $ from preprocessor
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
TEST_CASE(typeConstToConstType); // change "int const" to "const int".
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax1);
TEST_CASE(wrong_syntax2);
@ -640,11 +638,6 @@ private:
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
}
void typeConstToConstType() { // change "int const" to "const int".
ASSERT_EQUALS("const int x ;", tokenizeAndStringify("int const x;"));
ASSERT_EQUALS("const struct X x ;", tokenizeAndStringify("struct X const x;"));
}
void wrong_syntax1() {
{
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
@ -3293,7 +3286,7 @@ private:
{
const std::string code = "static int const SZ = 22;\n";
ASSERT_EQUALS("\n\n##file 0\n"
"1: const static int SZ@1 = 22 ;\n",
"1: static const int SZ@1 = 22 ;\n",
tokenizeDebugListing(code, false, "test.c"));
}
}
@ -5637,6 +5630,9 @@ private:
tokenizeAndStringify("void foo(){ int * const x;}"));
ASSERT_EQUALS("const int foo ( ) ;", tokenizeAndStringify("int const foo ();"));
ASSERT_EQUALS("const int x ;", tokenizeAndStringify("int const x;"));
ASSERT_EQUALS("const struct X x ;", tokenizeAndStringify("struct X const x;"));
}
void switchCase() {