Refactorized <Windows.h> type support:

- Changed some more Win32 simplifications of wide-character/string types to use wchar_t
- Added support for LPWSTR
- Fixed test case to ensure that simplifications also work for Win32W
This commit is contained in:
PKEuS 2012-11-11 15:40:06 +01:00
parent b15ff0c0e3
commit 5555e055f1
2 changed files with 23 additions and 16 deletions

View File

@ -5228,6 +5228,9 @@ void Tokenizer::simplifyPlatformTypes()
} else if (Token::Match(tok, "LPSTR|PSTR|PCHAR")) { } else if (Token::Match(tok, "LPSTR|PSTR|PCHAR")) {
tok->str("char"); tok->str("char");
tok->insertToken("*"); tok->insertToken("*");
} else if (Token::Match(tok, "PWSTR|PWCHAR")) {
tok->str("wchar_t");
tok->insertToken("*");
} else if (Token::Match(tok, "LPVOID|PVOID|HANDLE|HBITMAP|HBRUSH|HCOLORSPACE|HCURSOR|HDC|HFONT|HGDIOBJ|HGLOBAL|HICON|HINSTANCE|HKEY|HLOCAL|HMENU|HMETAFILE|HMODULE|HPALETTE|HPEN|HRGN|HRSRC|HWND|SERVICE_STATUS_HANDLE|SC_LOCK|SC_HANDLE|HACCEL|HCONV|HCONVLIST|HDDEDATA|HDESK|HDROP|HDWP|HENHMETAFILE|HHOOK|HKL|HMONITOR|HSZ|HWINSTA")) { } else if (Token::Match(tok, "LPVOID|PVOID|HANDLE|HBITMAP|HBRUSH|HCOLORSPACE|HCURSOR|HDC|HFONT|HGDIOBJ|HGLOBAL|HICON|HINSTANCE|HKEY|HLOCAL|HMENU|HMETAFILE|HMODULE|HPALETTE|HPEN|HRGN|HRSRC|HWND|SERVICE_STATUS_HANDLE|SC_LOCK|SC_HANDLE|HACCEL|HCONV|HCONVLIST|HDDEDATA|HDESK|HDROP|HDWP|HENHMETAFILE|HHOOK|HKL|HMONITOR|HSZ|HWINSTA")) {
tok->str("void"); tok->str("void");
tok->insertToken("*"); tok->insertToken("*");
@ -5235,7 +5238,7 @@ void Tokenizer::simplifyPlatformTypes()
tok->str("void"); tok->str("void");
tok->insertToken("*"); tok->insertToken("*");
tok->insertToken("*"); tok->insertToken("*");
} else if (Token::Match(tok, "LPWORD|PWORD|PWSTR|PWCHAR|PUSHORT")) { } else if (Token::Match(tok, "LPWORD|PWORD|PUSHORT")) {
tok->str("unsigned"); tok->str("unsigned");
tok->insertToken("*"); tok->insertToken("*");
tok->insertToken("short"); tok->insertToken("short");
@ -5274,9 +5277,8 @@ void Tokenizer::simplifyPlatformTypes()
tok->str("char"); tok->str("char");
tok->insertToken("*"); tok->insertToken("*");
} else { } else {
tok->str("unsigned"); tok->str("wchar_t");
tok->insertToken("*"); tok->insertToken("*");
tok->insertToken("short");
} }
} else if (Token::Match(tok, "PCTSTR|LPCTSTR")) { } else if (Token::Match(tok, "PCTSTR|LPCTSTR")) {
tok->str("const"); tok->str("const");
@ -5285,8 +5287,7 @@ void Tokenizer::simplifyPlatformTypes()
tok->insertToken("char"); tok->insertToken("char");
} else { } else {
tok->insertToken("*"); tok->insertToken("*");
tok->insertToken("short"); tok->insertToken("wchar_t");
tok->insertToken("unsigned");
} }
} else if (Token::Match(tok, "ULONG64|DWORD64")) { } else if (Token::Match(tok, "ULONG64|DWORD64")) {
tok->str("unsigned"); tok->str("unsigned");
@ -5303,11 +5304,13 @@ void Tokenizer::simplifyPlatformTypes()
} else { } else {
tok->str("int"); tok->str("int");
} }
} else if (tok->str() == "LPWSTR") {
tok->str("wchar_t");
tok->insertToken("*");
} else if (tok->str() == "LPCWSTR") { } else if (tok->str() == "LPCWSTR") {
tok->str("const"); tok->str("const");
tok->insertToken("*"); tok->insertToken("*");
tok->insertToken("short"); tok->insertToken("wchar_t");
tok->insertToken("unsigned");
} }
} }
} }

View File

@ -7012,7 +7012,6 @@ private:
} }
void platformWin32() { void platformWin32() {
// WIN32A
const char code[] = "unsigned int sizeof_short = sizeof(short);" const char code[] = "unsigned int sizeof_short = sizeof(short);"
"unsigned int sizeof_unsigned_short = sizeof(unsigned short);" "unsigned int sizeof_unsigned_short = sizeof(unsigned short);"
"unsigned int sizeof_int = sizeof(int);" "unsigned int sizeof_int = sizeof(int);"
@ -7110,6 +7109,7 @@ private:
"ULONG64 ulong64;" "ULONG64 ulong64;"
"HALF_PTR half_ptr;" "HALF_PTR half_ptr;"
"INT_PTR int_ptr;" "INT_PTR int_ptr;"
"LPWSTR lpcwstr;"
"LPCWSTR lpcwstr;"; "LPCWSTR lpcwstr;";
const char expected[] = "unsigned int sizeof_short ; sizeof_short = 2 ; " const char expected[] = "unsigned int sizeof_short ; sizeof_short = 2 ; "
@ -7200,7 +7200,7 @@ private:
"void * hmonitor ; " "void * hmonitor ; "
"void * hsz ; " "void * hsz ; "
"void * hwinsta ; " "void * hwinsta ; "
"unsigned short * pwchar ; " "wchar_t * pwchar ; "
"unsigned short * pushort ; " "unsigned short * pushort ; "
"unsigned int uint_ptr ; " "unsigned int uint_ptr ; "
"unsigned int wparam ; " "unsigned int wparam ; "
@ -7209,9 +7209,13 @@ private:
"unsigned long ulong64 ; " "unsigned long ulong64 ; "
"short half_ptr ; " "short half_ptr ; "
"int int_ptr ; " "int int_ptr ; "
"const unsigned short * lpcwstr ;"; "wchar_t * lpcwstr ; "
"const wchar_t * lpcwstr ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Win32A)); // These types should be defined the same on all Win32 platforms
std::string win32A = tokenizeAndStringify(code, true, true, Settings::Win32A);
ASSERT_EQUALS(expected, win32A);
ASSERT_EQUALS(win32A, tokenizeAndStringify(code, true, true, Settings::Win32W));
} }
void platformWin32A() { void platformWin32A() {
@ -7284,10 +7288,10 @@ private:
"}"; "}";
const char expected[] = "wchar_t wc ; " const char expected[] = "wchar_t wc ; "
"wchar_t c ; " "wchar_t c ; "
"unsigned short * ptstr ; " "wchar_t * ptstr ; "
"unsigned short * lptstr ; " "wchar_t * lptstr ; "
"const unsigned short * pctstr ; " "const wchar_t * pctstr ; "
"const unsigned short * lpctstr ; " "const wchar_t * lpctstr ; "
"unsigned char tbyte ; " "unsigned char tbyte ; "
"void foo ( ) { " "void foo ( ) { "
"wchar_t tc ; tc = \'c\' ; " "wchar_t tc ; tc = \'c\' ; "
@ -7296,7 +7300,7 @@ private:
"wcscpy ( dst , src ) ; " "wcscpy ( dst , src ) ; "
"dst [ 0 ] = 0 ; " "dst [ 0 ] = 0 ; "
"wcscat ( dst , src ) ; " "wcscat ( dst , src ) ; "
"unsigned short * d ; d = wcsdup ( str ) ; " "wchar_t * d ; d = wcsdup ( str ) ; "
"wprintf ( \"Hello world!\n\" ) ; " "wprintf ( \"Hello world!\n\" ) ; "
"swprintf ( dst , \"Hello!\n\" ) ; " "swprintf ( dst , \"Hello!\n\" ) ; "
"snwprintf ( dst , sizeof ( dst ) / sizeof ( wchar_t ) , \"Hello world!\n\" ) ; " "snwprintf ( dst , sizeof ( dst ) / sizeof ( wchar_t ) , \"Hello world!\n\" ) ; "