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")) {
tok->str("char");
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")) {
tok->str("void");
tok->insertToken("*");
@ -5235,7 +5238,7 @@ void Tokenizer::simplifyPlatformTypes()
tok->str("void");
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->insertToken("*");
tok->insertToken("short");
@ -5274,9 +5277,8 @@ void Tokenizer::simplifyPlatformTypes()
tok->str("char");
tok->insertToken("*");
} else {
tok->str("unsigned");
tok->str("wchar_t");
tok->insertToken("*");
tok->insertToken("short");
}
} else if (Token::Match(tok, "PCTSTR|LPCTSTR")) {
tok->str("const");
@ -5285,8 +5287,7 @@ void Tokenizer::simplifyPlatformTypes()
tok->insertToken("char");
} else {
tok->insertToken("*");
tok->insertToken("short");
tok->insertToken("unsigned");
tok->insertToken("wchar_t");
}
} else if (Token::Match(tok, "ULONG64|DWORD64")) {
tok->str("unsigned");
@ -5303,11 +5304,13 @@ void Tokenizer::simplifyPlatformTypes()
} else {
tok->str("int");
}
} else if (tok->str() == "LPWSTR") {
tok->str("wchar_t");
tok->insertToken("*");
} else if (tok->str() == "LPCWSTR") {
tok->str("const");
tok->insertToken("*");
tok->insertToken("short");
tok->insertToken("unsigned");
tok->insertToken("wchar_t");
}
}
}

View File

@ -7012,7 +7012,6 @@ private:
}
void platformWin32() {
// WIN32A
const char code[] = "unsigned int sizeof_short = sizeof(short);"
"unsigned int sizeof_unsigned_short = sizeof(unsigned short);"
"unsigned int sizeof_int = sizeof(int);"
@ -7110,6 +7109,7 @@ private:
"ULONG64 ulong64;"
"HALF_PTR half_ptr;"
"INT_PTR int_ptr;"
"LPWSTR lpcwstr;"
"LPCWSTR lpcwstr;";
const char expected[] = "unsigned int sizeof_short ; sizeof_short = 2 ; "
@ -7200,7 +7200,7 @@ private:
"void * hmonitor ; "
"void * hsz ; "
"void * hwinsta ; "
"unsigned short * pwchar ; "
"wchar_t * pwchar ; "
"unsigned short * pushort ; "
"unsigned int uint_ptr ; "
"unsigned int wparam ; "
@ -7209,9 +7209,13 @@ private:
"unsigned long ulong64 ; "
"short half_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() {
@ -7284,10 +7288,10 @@ private:
"}";
const char expected[] = "wchar_t wc ; "
"wchar_t c ; "
"unsigned short * ptstr ; "
"unsigned short * lptstr ; "
"const unsigned short * pctstr ; "
"const unsigned short * lpctstr ; "
"wchar_t * ptstr ; "
"wchar_t * lptstr ; "
"const wchar_t * pctstr ; "
"const wchar_t * lpctstr ; "
"unsigned char tbyte ; "
"void foo ( ) { "
"wchar_t tc ; tc = \'c\' ; "
@ -7296,7 +7300,7 @@ private:
"wcscpy ( dst , src ) ; "
"dst [ 0 ] = 0 ; "
"wcscat ( dst , src ) ; "
"unsigned short * d ; d = wcsdup ( str ) ; "
"wchar_t * d ; d = wcsdup ( str ) ; "
"wprintf ( \"Hello world!\n\" ) ; "
"swprintf ( dst , \"Hello!\n\" ) ; "
"snwprintf ( dst , sizeof ( dst ) / sizeof ( wchar_t ) , \"Hello world!\n\" ) ; "