diff --git a/lib/token.cpp b/lib/token.cpp index db592e150..ba5e7c51c 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -562,7 +562,7 @@ size_t Token::getStrLength(const Token *tok) bool Token::isStandardType() const { bool ret = false; - const char *type[] = {"bool", "char", "short", "int", "long", "float", "double", "size_t", "__int64", 0}; + const char *type[] = {"bool", "char", "short", "int", "long", "float", "double", "size_t", "__int8", "__int16", "__int32", "__int64", 0}; for (int i = 0; type[i]; i++) ret |= (_str == type[i]); return ret; @@ -571,7 +571,7 @@ bool Token::isStandardType() const bool Token::isIntegerType() const { bool ret = false; - const char *type[] = {"char", "short", "int", "long", "size_t", "__int64", 0}; + const char *type[] = {"char", "short", "int", "long", "size_t", "__int8", "__int16", "__int32", "__int64", 0}; for (int i = 0; type[i]; i++) ret |= (_str == type[i]); return ret; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7f146384b..0e288bf13 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1794,9 +1794,6 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s } } - // simplify bit fields.. - simplifyBitfields(); - // Remove __declspec() simplifyDeclspec(); @@ -1831,6 +1828,9 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s // unsigned long long int => long _isUnsigned=true,_isLong=true simplifyStdType(); + // simplify bit fields.. + simplifyBitfields(); + // Use "<" comparison instead of ">" simplifyComparisonOrder(); @@ -4970,14 +4970,14 @@ void Tokenizer::simplifyStdType() for (Token *tok = _tokens; tok; tok = tok->next()) { // long unsigned => unsigned long - if (Token::Match(tok, "long|short|int|char|_int64 unsigned|signed")) + if (Token::Match(tok, "char|short|int|long|__int8|__int16|__int32|__int64 unsigned|signed")) { std::string temp = tok->str(); tok->str(tok->next()->str()); tok->next()->str(temp); } - if (!Token::Match(tok, "unsigned|signed|long|char|short|int|__int64")) + if (!Token::Match(tok, "unsigned|signed|char|short|int|long|__int8|__int16|__int32|__int64")) continue; // check if signed or unsigned specified @@ -4994,7 +4994,13 @@ void Tokenizer::simplifyStdType() tok->isSigned(!isUnsigned); } - if (Token::Match(tok, "__int64")) + if (Token::Match(tok, "__int8")) + tok->str("char"); + else if (Token::Match(tok, "__int16")) + tok->str("short"); + else if (Token::Match(tok, "__int32")) + tok->str("int"); + else if (Token::Match(tok, "__int64")) { tok->str("long"); tok->isLong(true); @@ -8006,7 +8012,7 @@ static bool isAllUpper(const Token *type) static bool isBitfieldType(const Token *type) { - if (Token::Match(type, "signed|unsigned|int|long|bool|char|short|__int64") || isAllUpper(type)) + if (Token::Match(type, "bool|char|short|int|long") || isAllUpper(type)) return true; return false; } @@ -8022,20 +8028,15 @@ void Tokenizer::simplifyBitfields() last = tok->tokAt(5); Token::eraseTokens(tok->tokAt(2), tok->tokAt(5)); } - else if (Token::Match(tok, ";|{|public:|protected:|private: signed|unsigned %type% %var% : %num% ;|,") && isBitfieldType(tok->tokAt(2))) - { - last = tok->tokAt(6); - Token::eraseTokens(tok->tokAt(3), tok->tokAt(6)); - } else if (Token::Match(tok, ";|{|public:|protected:|private: const %type% %var% : %num% ;|,") && isBitfieldType(tok->tokAt(2))) { last = tok->tokAt(6); Token::eraseTokens(tok->tokAt(3), tok->tokAt(6)); } - else if (Token::Match(tok, ";|{|public:|protected:|private: const signed|unsigned %type% %var% : %num% ;|,") && isBitfieldType(tok->tokAt(3))) + else if (Token::Match(tok, ";|{|public:|protected:|private: %type% : %num% ;") && isBitfieldType(tok->next())) { - last = tok->tokAt(7); - Token::eraseTokens(tok->tokAt(4), tok->tokAt(7)); + Token::eraseTokens(tok->tokAt(0), tok->tokAt(5)); + tok = tok->previous(); } if (last && last->str() == ",") @@ -8046,14 +8047,9 @@ void Tokenizer::simplifyBitfields() Token *tok2 = tok->next(); tok1->insertToken(tok2->str()); tok1 = tok1->next(); - tok2 = tok2->next(); - - while (tok2->str() != last->previous()->str()) - { - tok1->insertToken(tok2->str()); - tok1 = tok1->next(); - tok2 = tok2->next(); - } + tok1->isSigned(tok2->isSigned()); + tok1->isUnsigned(tok2->isUnsigned()); + tok1->isLong(tok2->isLong()); } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5c6e66447..c91db4d66 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4313,38 +4313,65 @@ private: const char code5[] = "struct A { long x : 3; };"; ASSERT_EQUALS("struct A { long x ; } ;", tokenizeAndStringify(code5,false)); - const char code6[] = "struct A { __int64 x : 3; };"; - ASSERT_EQUALS("struct A { long long x ; } ;", tokenizeAndStringify(code6,false)); + const char code6[] = "struct A { __int8 x : 3; };"; + ASSERT_EQUALS("struct A { char x ; } ;", tokenizeAndStringify(code6,false)); - const char code7[] = "struct A { unsigned char x : 3; };"; - ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringify(code7,false)); + const char code7[] = "struct A { __int16 x : 3; };"; + ASSERT_EQUALS("struct A { short x ; } ;", tokenizeAndStringify(code7,false)); - const char code8[] = "struct A { unsigned short x : 3; };"; - ASSERT_EQUALS("struct A { unsigned short x ; } ;", tokenizeAndStringify(code8,false)); + const char code8[] = "struct A { __int32 x : 3; };"; + ASSERT_EQUALS("struct A { int x ; } ;", tokenizeAndStringify(code8,false)); - const char code9[] = "struct A { unsigned int x : 3; };"; - ASSERT_EQUALS("struct A { unsigned int x ; } ;", tokenizeAndStringify(code9,false)); + const char code9[] = "struct A { __int64 x : 3; };"; + ASSERT_EQUALS("struct A { long long x ; } ;", tokenizeAndStringify(code9,false)); - const char code10[] = "struct A { unsigned long x : 3; };"; - ASSERT_EQUALS("struct A { unsigned long x ; } ;", tokenizeAndStringify(code10,false)); + const char code10[] = "struct A { unsigned char x : 3; };"; + ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringify(code10,false)); - const char code11[] = "struct A { unsigned __int64 x : 3; };"; - ASSERT_EQUALS("struct A { unsigned long long x ; } ;", tokenizeAndStringify(code11,false)); + const char code11[] = "struct A { unsigned short x : 3; };"; + ASSERT_EQUALS("struct A { unsigned short x ; } ;", tokenizeAndStringify(code11,false)); - const char code12[] = "struct A { signed char x : 3; };"; - ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringify(code12,false)); + const char code12[] = "struct A { unsigned int x : 3; };"; + ASSERT_EQUALS("struct A { unsigned int x ; } ;", tokenizeAndStringify(code12,false)); - const char code13[] = "struct A { signed short x : 3; };"; - ASSERT_EQUALS("struct A { signed short x ; } ;", tokenizeAndStringify(code13,false)); + const char code13[] = "struct A { unsigned long x : 3; };"; + ASSERT_EQUALS("struct A { unsigned long x ; } ;", tokenizeAndStringify(code13,false)); - const char code14[] = "struct A { signed int x : 3; };"; - ASSERT_EQUALS("struct A { signed int x ; } ;", tokenizeAndStringify(code14,false)); + const char code14[] = "struct A { unsigned __int8 x : 3; };"; + ASSERT_EQUALS("struct A { unsigned char x ; } ;", tokenizeAndStringify(code14,false)); - const char code15[] = "struct A { signed long x : 3; };"; - ASSERT_EQUALS("struct A { signed long x ; } ;", tokenizeAndStringify(code15,false)); + const char code15[] = "struct A { unsigned __int16 x : 3; };"; + ASSERT_EQUALS("struct A { unsigned short x ; } ;", tokenizeAndStringify(code15,false)); - const char code16[] = "struct A { signed __int64 x : 3; };"; - ASSERT_EQUALS("struct A { signed long long x ; } ;", tokenizeAndStringify(code16,false)); + const char code16[] = "struct A { unsigned __int32 x : 3; };"; + ASSERT_EQUALS("struct A { unsigned int x ; } ;", tokenizeAndStringify(code16,false)); + + const char code17[] = "struct A { unsigned __int64 x : 3; };"; + ASSERT_EQUALS("struct A { unsigned long long x ; } ;", tokenizeAndStringify(code17,false)); + + const char code18[] = "struct A { signed char x : 3; };"; + ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringify(code18,false)); + + const char code19[] = "struct A { signed short x : 3; };"; + ASSERT_EQUALS("struct A { signed short x ; } ;", tokenizeAndStringify(code19,false)); + + const char code20[] = "struct A { signed int x : 3; };"; + ASSERT_EQUALS("struct A { signed int x ; } ;", tokenizeAndStringify(code20,false)); + + const char code21[] = "struct A { signed long x : 3; };"; + ASSERT_EQUALS("struct A { signed long x ; } ;", tokenizeAndStringify(code21,false)); + + const char code22[] = "struct A { signed __int8 x : 3; };"; + ASSERT_EQUALS("struct A { signed char x ; } ;", tokenizeAndStringify(code22,false)); + + const char code23[] = "struct A { signed __int16 x : 3; };"; + ASSERT_EQUALS("struct A { signed short x ; } ;", tokenizeAndStringify(code23,false)); + + const char code24[] = "struct A { signed __int32 x : 3; };"; + ASSERT_EQUALS("struct A { signed int x ; } ;", tokenizeAndStringify(code24,false)); + + const char code25[] = "struct A { signed __int64 x : 3; };"; + ASSERT_EQUALS("struct A { signed long long x ; } ;", tokenizeAndStringify(code25,false)); } void bitfields2() @@ -4420,6 +4447,9 @@ private: { const char code1[] = "struct RGB { unsigned int r : 3, g : 3, b : 2; };"; ASSERT_EQUALS("struct RGB { unsigned int r ; unsigned int g ; unsigned int b ; } ;", tokenizeAndStringify(code1,false)); + + const char code2[] = "struct A { int a : 3; int : 3; int c : 3; };"; + ASSERT_EQUALS("struct A { int a ; int c ; } ;", tokenizeAndStringify(code2,false)); } void microsoftMFC()