diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 2dfda58d5..298fab1f9 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -476,11 +476,23 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[]) // replace "unsigned i" with "unsigned int i" unsignedint(); + // Split up variable declarations. simplifyVarDecl(); // Handle templates.. simplifyTemplates(); + // change array to pointer.. + for (Token *tok = _tokens; tok; tok = tok->next()) + { + if (Token::Match(tok, "%type% %var% [ ] [,;=]")) + { + tok->next()->deleteNext(); + tok->next()->deleteNext(); + tok->insertToken("*"); + } + } + return true; } //--------------------------------------------------------------------------- diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index bffd96132..d84ca8eac 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -66,6 +66,8 @@ private: TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )" TEST_CASE(declareVar); + TEST_CASE(declareArray); + TEST_CASE(dontRemoveIncrement); TEST_CASE(removePostIncrement); TEST_CASE(removePreIncrement); @@ -385,6 +387,12 @@ private: ASSERT_EQUALS(code, tok(code)); } + void declareArray() + { + const char code[] = "void f ( ) { char str [ ] = \"100\" ; } "; + const char expected[] = "void f ( ) { char * str ; str = \"100\" ; } "; + ASSERT_EQUALS(expected, tok(code)); + } void dontRemoveIncrement() {