Fix ticket #3530 (Add some windows data types to tokenizer)

This commit is contained in:
seb777 2012-01-18 12:57:41 +01:00
parent 3066bb3430
commit 0be8af5214
2 changed files with 139 additions and 23 deletions

View File

@ -5306,14 +5306,14 @@ void Tokenizer::simplifyPlatformTypes()
_settings->platformType == Settings::Win32W ||
_settings->platformType == Settings::Win64) {
for (Token *tok = _tokens; tok; tok = tok->next()) {
if (Token::Match(tok, "BOOL|INT|INT32"))
if (Token::Match(tok, "BOOL|INT|INT32|HFILE|LONG32"))
tok->str("int");
else if (Token::Match(tok, "BOOLEAN|BYTE|UCHAR")) {
tok->str("unsigned");
tok->insertToken("char");
} else if (tok->str() == "CHAR")
tok->str("char");
else if (Token::Match(tok, "DWORD|ULONG|COLORREF")) {
else if (Token::Match(tok, "DWORD|ULONG|COLORREF|LCID|LCTYPE|LGRPID")) {
tok->str("unsigned");
tok->insertToken("long");
} else if (Token::Match(tok, "DWORD_PTR|ULONG_PTR|SIZE_T")) {
@ -5323,21 +5323,19 @@ void Tokenizer::simplifyPlatformTypes()
tok->insertToken("long");
} else if (tok->str() == "FLOAT")
tok->str("float");
else if (tok->str() == "HRESULT")
else if (Token::Match(tok, "HRESULT|LONG"))
tok->str("long");
else if (tok->str() == "INT64") {
else if (Token::Match(tok, "INT64|LONG64")) {
tok->str("long");
tok->insertToken("long");
} else if (tok->str() == "LONG")
tok->str("long");
else if (Token::Match(tok, "LONG_PTR|LPARAM|LRESULT")) {
} else if (Token::Match(tok, "LONG_PTR|LPARAM|LRESULT|SSIZE_T")) {
tok->str("long");
if (_settings->platformType == Settings::Win64)
tok->insertToken("long");
} else if (Token::Match(tok, "LPBOOL|PBOOL")) {
tok->str("int");
tok->insertToken("*");
} else if (Token::Match(tok, "LPBYTE|PBOOLEAN|PBYTE")) {
} else if (Token::Match(tok, "LPBYTE|PBOOLEAN|PBYTE|PUCHAR")) {
tok->str("unsigned");
tok->insertToken("*");
tok->insertToken("char");
@ -5349,7 +5347,7 @@ void Tokenizer::simplifyPlatformTypes()
tok->str("const");
tok->insertToken("*");
tok->insertToken("void");
} else if (tok->str() == "LPDWORD") {
} else if (Token::Match(tok, "LPDWORD|LPCOLORREF|PDWORD|PULONG")) {
tok->str("unsigned");
tok->insertToken("*");
tok->insertToken("long");
@ -5362,28 +5360,31 @@ void Tokenizer::simplifyPlatformTypes()
} else if (Token::Match(tok, "LPSTR|PSTR|PCHAR")) {
tok->str("char");
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")) {
} 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("*");
} else if ((tok->str() == "PHANDLE")) {
tok->str("void");
tok->insertToken("*");
tok->insertToken("*");
} else if (Token::Match(tok, "LPWORD|PWORD")) {
} else if (Token::Match(tok, "LPWORD|PWORD|PWSTR|PWCHAR|PUSHORT")) {
tok->str("unsigned");
tok->insertToken("*");
tok->insertToken("short");
} else if (tok->str() == "SHORT")
tok->str("short");
else if (Token::Match(tok, "UINT|MMRESULT|SOCKET")) {
else if (Token::Match(tok, "UINT|MMRESULT|SOCKET|ULONG32|UINT32|DWORD32")) {
tok->str("unsigned");
tok->insertToken("int");
} else if (Token::Match(tok, "UINT_PTR|WPARAM")) {
tok->str("unsigned");
tok->insertToken("long");
if (_settings->platformType == Settings::Win64)
if (_settings->platformType == Settings::Win64) {
tok->insertToken("long");
} else if (Token::Match(tok, "USHORT|WORD|WCHAR|ATOM|wchar_t")) {
tok->insertToken("long");
} else {
tok->insertToken("int");
}
} else if (Token::Match(tok, "USHORT|WORD|WCHAR|ATOM|wchar_t|LANGID")) {
tok->str("unsigned");
tok->insertToken("short");
} else if (tok->str() == "VOID")
@ -5395,6 +5396,12 @@ void Tokenizer::simplifyPlatformTypes()
tok->str("unsigned");
tok->insertToken("short");
}
} else if (tok->str() == "TBYTE") {
tok->str("unsigned");
if (_settings->platformType == Settings::Win32A)
tok->insertToken("short");
else
tok->insertToken("char");
} else if (Token::Match(tok, "PTSTR|LPTSTR")) {
if (_settings->platformType == Settings::Win32A) {
tok->str("char");
@ -5405,16 +5412,35 @@ void Tokenizer::simplifyPlatformTypes()
tok->insertToken("short");
}
} else if (Token::Match(tok, "PCTSTR|LPCTSTR")) {
tok->str("const");
if (_settings->platformType == Settings::Win32A) {
tok->str("const");
tok->insertToken("*");
tok->insertToken("char");
} else {
tok->str("const");
tok->insertToken("*");
tok->insertToken("short");
tok->insertToken("unsigned");
}
} else if (Token::Match(tok, "ULONG64|DWORD64")) {
tok->str("unsigned");
tok->insertToken("long");
} else if (tok->str() == "HALF_PTR") {
if (_settings->platformType == Settings::Win64)
tok->str("int");
else
tok->str("short");
} else if (tok->str() == "INT_PTR") {
if (_settings->platformType == Settings::Win64) {
tok->str("long");
tok->insertToken("long");
} else {
tok->str("int");
}
} else if (tok->str() == "LPCWSTR") {
tok->str("const");
tok->insertToken("*");
tok->insertToken("short");
tok->insertToken("unsigned");
}
}
}

View File

@ -6104,6 +6104,7 @@ 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);"
@ -6163,7 +6164,45 @@ private:
"SIZE_T Q;"
"HRESULT R;"
"LONG_PTR S;"
"HANDLE T;";
"HANDLE T;"
"BOOL _bool;"
"HFILE hfile;"
"LONG32 long32;"
"LCID lcid;"
"LCTYPE lctype;"
"LGRPID lgrpid;"
"LONG64 long64;"
"SSIZE_T _ssize_t;"
"PUCHAR puchar;"
"LPCOLORREF lpcolorref;"
"PDWORD pdword;"
"PULONG pulong;"
"SERVICE_STATUS_HANDLE service_status_hanlde;"
"SC_LOCK sc_lock;"
"SC_HANDLE sc_handle;"
"HACCEL haccel;"
"HCONV hconv;"
"HCONVLIST hconvlist;"
"HDDEDATA hddedata;"
"HDESK hdesk;"
"HDROP hdrop;"
"HDWP hdwp;"
"HENHMETAFILE henhmetafile;"
"HHOOK hhook;"
"HKL hkl;"
"HMONITOR hmonitor;"
"HSZ hsz;"
"HWINSTA hwinsta;"
"PWCHAR pwchar;"
"PUSHORT pushort;"
"UINT_PTR uint_ptr;"
"WPARAM wparam;"
"LANGID langid;"
"DWORD64 dword64;"
"ULONG64 ulong64;"
"HALF_PTR half_ptr;"
"INT_PTR int_ptr;"
"LPCWSTR lpcwstr;";
const char expected[] = "unsigned int sizeof_short ; sizeof_short = 2 ; "
"unsigned int sizeof_unsigned_short ; sizeof_unsigned_short = 2 ; "
@ -6224,7 +6263,45 @@ private:
"unsigned long Q ; "
"long R ; "
"long S ; "
"void * T ;";
"void * T ; "
"int _bool ; "
"int hfile ; "
"int long32 ; "
"unsigned long lcid ; "
"unsigned long lctype ; "
"unsigned long lgrpid ; "
"long long long64 ; "
"long _ssize_t ; "
"unsigned char * puchar ; "
"unsigned long * lpcolorref ; "
"unsigned long * pdword ; "
"unsigned long * pulong ; "
"void * service_status_hanlde ; "
"void * sc_lock ; "
"void * sc_handle ; "
"void * haccel ; "
"void * hconv ; "
"void * hconvlist ; "
"void * hddedata ; "
"void * hdesk ; "
"void * hdrop ; "
"void * hdwp ; "
"void * henhmetafile ; "
"void * hhook ; "
"void * hkl ; "
"void * hmonitor ; "
"void * hsz ; "
"void * hwinsta ; "
"unsigned short * pwchar ; "
"unsigned short * pushort ; "
"unsigned int uint_ptr ; "
"unsigned int wparam ; "
"unsigned short langid ; "
"unsigned long dword64 ; "
"unsigned long ulong64 ; "
"short half_ptr ; "
"int int_ptr ; "
"const unsigned short * lpcwstr ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Win32A));
}
@ -6249,7 +6326,8 @@ private:
" _sntprintf(dst, sizeof(dst) / sizeof(TCHAR), _T(\"Hello world!\n\"));"
" _tscanf(_T(\"%s\"), dst);"
" _stscanf(dst, _T(\"%s\"), dst);"
"}";
"}"
"TBYTE tbyte;";
const char expected[] = "unsigned short wc ; "
"char c ; "
"char * ptstr ; "
@ -6269,7 +6347,8 @@ private:
"snprintf ( dst , sizeof ( dst ) / sizeof ( char ) , \"Hello world!\n\" ) ; "
"scanf ( \"%s\" , dst ) ; "
"sscanf ( dst , \"%s\" , dst ) ; "
"}";
"} "
"unsigned short tbyte ;";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, false, true, Settings::Win32A));
}
@ -6280,6 +6359,7 @@ private:
"LPTSTR lptstr;"
"PCTSTR pctstr;"
"LPCTSTR lpctstr;"
"TBYTE tbyte;"
"void foo() {"
" TCHAR tc = _T(\'c\');"
" TCHAR src[10] = _T(\"123456789\");"
@ -6300,6 +6380,7 @@ private:
"unsigned short * lptstr ; "
"const unsigned short * pctstr ; "
"const unsigned short * lpctstr ; "
"unsigned char tbyte ; "
"void foo ( ) { "
"unsigned short tc ; tc = \'c\' ; "
"unsigned short src [ 10 ] = \"123456789\" ; "
@ -6342,7 +6423,11 @@ private:
"SIZE_T Q;"
"HRESULT R;"
"LONG_PTR S;"
"HANDLE T;";
"HANDLE T;"
"SSIZE_T _ssize_t;"
"UINT_PTR uint_ptr;"
"WPARAM wparam;"
"INT_PTR int_ptr;";
const char expected[] = "unsigned int sizeof_short ; sizeof_short = 2 ; "
"unsigned int sizeof_unsigned_short ; sizeof_unsigned_short = 2 ; "
@ -6368,7 +6453,12 @@ private:
"unsigned long long Q ; "
"long R ; "
"long long S ; "
"void * T ;";
"void * T ; "
"long long _ssize_t ; "
"unsigned long long uint_ptr ; "
"unsigned long long wparam ; "
"long long int_ptr ;"
;
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Win64));
}