From dd0e5b6a24c0048a63bb7d511da619a9982dd97d Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sat, 8 Jan 2011 13:40:25 -0600 Subject: [PATCH 1/2] Remove keywords before running simplifyTypedef --- lib/tokenize.cpp | 12 ++++++------ test/testsimplifytokens.cpp | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6c963dbeca2..2bc85acc94a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2367,6 +2367,12 @@ bool Tokenizer::tokenize(std::istream &code, // remove Borland stuff.. simplifyBorland(); + // Remove "volatile", "inline", "register", and "restrict" + simplifyKeyword(); + + // Remove __builtin_expect, likely and unlikely + simplifyBuiltinExpect(); + // typedef.. simplifyTypedef(); @@ -2388,12 +2394,6 @@ bool Tokenizer::tokenize(std::istream &code, } } - // Remove "volatile", "inline", "register", and "restrict" - simplifyKeyword(); - - // Remove __builtin_expect, likely and unlikely - simplifyBuiltinExpect(); - // collapse compound standard types into a single token // unsigned long long int => long _isUnsigned=true,_isLong=true simplifyStdType(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index dc19bb1abae..9ab0685fe1a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -6279,6 +6279,7 @@ class TestSimplifyTokens : public TestFixture ASSERT_EQUALS("int * p ;", tok("int * restrict p;", true)); ASSERT_EQUALS("int * * p ;", tok("int * restrict * p;", true)); ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * restrict a, float * restrict b);", true)); + ASSERT_EQUALS("; int * p ;", tok("typedef int * __restrict__ rint; rint p;", true)); } void simplifyCallingConvention() From b6af592702a211a78e7b811a5d33051b9a8977dc Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sat, 8 Jan 2011 13:44:15 -0600 Subject: [PATCH 2/2] Treat __restrict just like restrict/__restrict__ --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2bc85acc94a..79d3deb279b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8820,7 +8820,7 @@ void Tokenizer::simplifyAttribute() // Remove "volatile", "inline", "register", and "restrict" void Tokenizer::simplifyKeyword() { - const char pattern[] = "volatile|inline|__inline|__forceinline|register|restrict|__restrict__"; + const char pattern[] = "volatile|inline|__inline|__forceinline|register|restrict|__restrict|__restrict__"; while (Token::Match(_tokens, pattern)) { _tokens->deleteThis(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 9ab0685fe1a..b27f58259cb 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -6273,7 +6273,7 @@ class TestSimplifyTokens : public TestFixture ASSERT_EQUALS("int foo ( ) { }", tok("__forceinline int foo ( ) { }", true)); ASSERT_EQUALS("if ( a ) { }", tok("if ( likely ( a ) ) { }", true)); ASSERT_EQUALS("if ( a ) { }", tok("if ( unlikely ( a ) ) { }", true)); - ASSERT_EQUALS("int * p ;", tok("int * __restrict__ p;", true)); + ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", true)); ASSERT_EQUALS("int * * p ;", tok("int * __restrict__ * p;", true)); ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * __restrict__ a, float * __restrict__ b);", true)); ASSERT_EQUALS("int * p ;", tok("int * restrict p;", true));