start adding Windows wide character support

This commit is contained in:
Robert Reif 2011-09-24 16:02:56 -04:00
parent f97424b242
commit 545aa9e55b
2 changed files with 119 additions and 35 deletions

View File

@ -6762,7 +6762,7 @@ void Tokenizer::simplifyPlatformTypes()
else else
tok->insertToken("long"); tok->insertToken("long");
} }
else if (Token::Match(tok, "USHORT|WORD")) else if (Token::Match(tok, "USHORT|WORD|WCHAR|wchar_t"))
{ {
tok->str("unsigned"); tok->str("unsigned");
tok->insertToken("short"); tok->insertToken("short");
@ -6773,6 +6773,11 @@ void Tokenizer::simplifyPlatformTypes()
{ {
if (_settings->platformType == Settings::Win32A) if (_settings->platformType == Settings::Win32A)
tok->str("char"); tok->str("char");
else
{
tok->str("unsigned");
tok->insertToken("short");
}
} }
else if (Token::Match(tok, "PTSTR|LPTSTR")) else if (Token::Match(tok, "PTSTR|LPTSTR"))
{ {
@ -6781,6 +6786,12 @@ void Tokenizer::simplifyPlatformTypes()
tok->str("char"); tok->str("char");
tok->insertToken("*"); tok->insertToken("*");
} }
else
{
tok->str("unsigned");
tok->insertToken("*");
tok->insertToken("short");
}
} }
else if (Token::Match(tok, "PCTSTR|LPCTSTR")) else if (Token::Match(tok, "PCTSTR|LPCTSTR"))
{ {
@ -6790,6 +6801,13 @@ void Tokenizer::simplifyPlatformTypes()
tok->insertToken("*"); tok->insertToken("*");
tok->insertToken("char"); tok->insertToken("char");
} }
else
{
tok->str("const");
tok->insertToken("*");
tok->insertToken("short");
tok->insertToken("unsigned");
}
} }
} }
} }
@ -10561,40 +10579,77 @@ void Tokenizer::simplifyMicrosoftMemoryFunctions()
void Tokenizer::simplifyMicrosoftStringFunctions() void Tokenizer::simplifyMicrosoftStringFunctions()
{ {
// skip if not Windows // skip if not Windows
if (_settings->platformType != Settings::Win32A) if (_settings->platformType == Settings::Win32A)
return;
for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (Token::simpleMatch(tok, "_tcscpy (")) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
tok->str("strcpy"); if (Token::simpleMatch(tok, "_tcscpy ("))
{
tok->str("strcpy");
}
else if (Token::simpleMatch(tok, "_tcscat ("))
{
tok->str("strcat");
}
else if (Token::simpleMatch(tok, "_tcsncpy ("))
{
tok->str("strncpy");
}
else if (Token::simpleMatch(tok, "_tcsncat ("))
{
tok->str("strncat");
}
else if (Token::simpleMatch(tok, "_tcslen ("))
{
tok->str("strlen");
}
else if (Token::simpleMatch(tok, "_tcsnlen ("))
{
tok->str("strnlen");
}
else if (Token::Match(tok, "_T ( %str% )"))
{
tok->deleteThis();
tok->deleteThis();
tok->deleteNext();
}
} }
else if (Token::simpleMatch(tok, "_tcscat (")) }
else if (_settings->platformType == Settings::Win32W ||
_settings->platformType == Settings::Win64)
{
for (Token *tok = _tokens; tok; tok = tok->next())
{ {
tok->str("strcat"); if (Token::simpleMatch(tok, "_tcscpy ("))
} {
else if (Token::simpleMatch(tok, "_tcsncpy (")) tok->str("wcscpy");
{ }
tok->str("strncpy"); else if (Token::simpleMatch(tok, "_tcscat ("))
} {
else if (Token::simpleMatch(tok, "_tcsncat (")) tok->str("wcscat");
{ }
tok->str("strncat"); else if (Token::simpleMatch(tok, "_tcsncpy ("))
} {
else if (Token::simpleMatch(tok, "_tcslen (")) tok->str("wcsncpy");
{ }
tok->str("strlen"); else if (Token::simpleMatch(tok, "_tcsncat ("))
} {
else if (Token::simpleMatch(tok, "_tcsnlen (")) tok->str("wcsncat");
{ }
tok->str("strnlen"); else if (Token::simpleMatch(tok, "_tcslen ("))
} {
else if (Token::Match(tok, "_T ( %str% )")) tok->str("wcslen");
{ }
tok->deleteThis(); else if (Token::simpleMatch(tok, "_tcsnlen ("))
tok->deleteThis(); {
tok->deleteNext(); tok->str("wcsnlen");
}
else if (Token::Match(tok, "_T ( %str% )"))
{
tok->deleteThis();
tok->deleteThis();
tok->deleteNext();
}
} }
} }
} }

View File

@ -6094,7 +6094,8 @@ private:
void platformWin32A() void platformWin32A()
{ {
const char code[] = "TCHAR c;" const char code[] = "wchar_t wc;"
"TCHAR c;"
"PTSTR ptstr;" "PTSTR ptstr;"
"LPTSTR lptstr;" "LPTSTR lptstr;"
"PCTSTR pctstr;" "PCTSTR pctstr;"
@ -6104,9 +6105,10 @@ private:
" TCHAR dst[10];" " TCHAR dst[10];"
" _tcscpy(dst, src);" " _tcscpy(dst, src);"
" dst[0] = 0;" " dst[0] = 0;"
" _tcscat(dst, str);" " _tcscat(dst, src);"
"}"; "}";
const char expected[] = "char c ; " const char expected[] = "unsigned short wc ; "
"char c ; "
"char * ptstr ; " "char * ptstr ; "
"char * lptstr ; " "char * lptstr ; "
"const char * pctstr ; " "const char * pctstr ; "
@ -6116,13 +6118,40 @@ private:
"char dst [ 10 ] ; " "char dst [ 10 ] ; "
"strcpy ( dst , src ) ; " "strcpy ( dst , src ) ; "
"dst [ 0 ] = 0 ; " "dst [ 0 ] = 0 ; "
"strcat ( dst , str ) ; " "strcat ( dst , src ) ; "
"}"; "}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false, true, Settings::Win32A)); ASSERT_EQUALS(expected, tokenizeAndStringify(code, false, true, Settings::Win32A));
} }
void platformWin32W() void platformWin32W()
{ {
const char code[] = "wchar_t wc;"
"TCHAR c;"
"PTSTR ptstr;"
"LPTSTR lptstr;"
"PCTSTR pctstr;"
"LPCTSTR lpctstr;"
"void foo() {"
" TCHAR src[10] = _T(\"123456789\");"
" TCHAR dst[10];"
" _tcscpy(dst, src);"
" dst[0] = 0;"
" _tcscat(dst, src);"
"}";
const char expected[] = "unsigned short wc ; "
"unsigned short c ; "
"unsigned short * ptstr ; "
"unsigned short * lptstr ; "
"const unsigned short * pctstr ; "
"const unsigned short * lpctstr ; "
"void foo ( ) { "
"unsigned short src [ 10 ] = \"123456789\" ; "
"unsigned short dst [ 10 ] ; "
"wcscpy ( dst , src ) ; "
"dst [ 0 ] = 0 ; "
"wcscat ( dst , src ) ; "
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false, true, Settings::Win32W));
} }
void platformWin64() void platformWin64()