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
tok->insertToken("long");
}
else if (Token::Match(tok, "USHORT|WORD"))
else if (Token::Match(tok, "USHORT|WORD|WCHAR|wchar_t"))
{
tok->str("unsigned");
tok->insertToken("short");
@ -6773,6 +6773,11 @@ void Tokenizer::simplifyPlatformTypes()
{
if (_settings->platformType == Settings::Win32A)
tok->str("char");
else
{
tok->str("unsigned");
tok->insertToken("short");
}
}
else if (Token::Match(tok, "PTSTR|LPTSTR"))
{
@ -6781,6 +6786,12 @@ void Tokenizer::simplifyPlatformTypes()
tok->str("char");
tok->insertToken("*");
}
else
{
tok->str("unsigned");
tok->insertToken("*");
tok->insertToken("short");
}
}
else if (Token::Match(tok, "PCTSTR|LPCTSTR"))
{
@ -6790,6 +6801,13 @@ void Tokenizer::simplifyPlatformTypes()
tok->insertToken("*");
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()
{
// skip if not Windows
if (_settings->platformType != Settings::Win32A)
return;
for (Token *tok = _tokens; tok; tok = tok->next())
if (_settings->platformType == Settings::Win32A)
{
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");
}
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();
if (Token::simpleMatch(tok, "_tcscpy ("))
{
tok->str("wcscpy");
}
else if (Token::simpleMatch(tok, "_tcscat ("))
{
tok->str("wcscat");
}
else if (Token::simpleMatch(tok, "_tcsncpy ("))
{
tok->str("wcsncpy");
}
else if (Token::simpleMatch(tok, "_tcsncat ("))
{
tok->str("wcsncat");
}
else if (Token::simpleMatch(tok, "_tcslen ("))
{
tok->str("wcslen");
}
else if (Token::simpleMatch(tok, "_tcsnlen ("))
{
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()
{
const char code[] = "TCHAR c;"
const char code[] = "wchar_t wc;"
"TCHAR c;"
"PTSTR ptstr;"
"LPTSTR lptstr;"
"PCTSTR pctstr;"
@ -6104,9 +6105,10 @@ private:
" TCHAR dst[10];"
" _tcscpy(dst, src);"
" 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 * lptstr ; "
"const char * pctstr ; "
@ -6116,13 +6118,40 @@ private:
"char dst [ 10 ] ; "
"strcpy ( dst , src ) ; "
"dst [ 0 ] = 0 ; "
"strcat ( dst , str ) ; "
"strcat ( dst , src ) ; "
"}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false, true, Settings::Win32A));
}
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()