Moved Tokenizer::typeConstToConstType() to Tokenizer::simplifyConst()
This commit is contained in:
parent
9a375744a4
commit
489df29346
|
@ -1947,9 +1947,6 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
tok = fortok;
|
tok = fortok;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// Convert "type const" to "const type"
|
|
||||||
typeConstToConstType();
|
|
||||||
|
|
||||||
simplifyConst();
|
simplifyConst();
|
||||||
|
|
||||||
// struct simplification "struct S {} s; => struct S { } ; S s ;
|
// struct simplification "struct S {} s; => struct S { } ; S s ;
|
||||||
|
@ -8084,24 +8081,17 @@ 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()
|
void Tokenizer::simplifyConst()
|
||||||
{
|
{
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "%type% const") &&
|
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->previous() || Token::Match(tok->previous(), "[;{}(,]")) &&
|
||||||
tok->str().find(":") == std::string::npos &&
|
tok->str().find(":") == std::string::npos &&
|
||||||
tok->str() != "operator") {
|
tok->str() != "operator") {
|
||||||
|
|
|
@ -480,12 +480,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void simplifyComparisonOrder();
|
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;"
|
* Change "int const x;" into "const int x;"
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -57,8 +57,6 @@ private:
|
||||||
TEST_CASE(tokenize22); // special marker $ from preprocessor
|
TEST_CASE(tokenize22); // special marker $ from preprocessor
|
||||||
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
|
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
|
||||||
|
|
||||||
TEST_CASE(typeConstToConstType); // change "int const" to "const int".
|
|
||||||
|
|
||||||
// don't freak out when the syntax is wrong
|
// don't freak out when the syntax is wrong
|
||||||
TEST_CASE(wrong_syntax1);
|
TEST_CASE(wrong_syntax1);
|
||||||
TEST_CASE(wrong_syntax2);
|
TEST_CASE(wrong_syntax2);
|
||||||
|
@ -640,11 +638,6 @@ private:
|
||||||
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
|
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() {
|
void wrong_syntax1() {
|
||||||
{
|
{
|
||||||
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
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";
|
const std::string code = "static int const SZ = 22;\n";
|
||||||
ASSERT_EQUALS("\n\n##file 0\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"));
|
tokenizeDebugListing(code, false, "test.c"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5637,6 +5630,9 @@ private:
|
||||||
tokenizeAndStringify("void foo(){ int * const x;}"));
|
tokenizeAndStringify("void foo(){ int * const x;}"));
|
||||||
|
|
||||||
ASSERT_EQUALS("const int foo ( ) ;", tokenizeAndStringify("int const foo ();"));
|
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() {
|
void switchCase() {
|
||||||
|
|
Loading…
Reference in New Issue