Added support for sizeof(wchar_t). Improved <Windows.h> type testing for Win64 platform.

This commit is contained in:
PKEuS 2012-11-11 16:16:17 +01:00
parent 5555e055f1
commit e5ebb49312
4 changed files with 91 additions and 63 deletions

View File

@ -147,6 +147,7 @@ bool Settings::platform(PlatformType type)
sizeof_float = sizeof(float); sizeof_float = sizeof(float);
sizeof_double = sizeof(double); sizeof_double = sizeof(double);
sizeof_long_double = sizeof(long double); sizeof_long_double = sizeof(long double);
sizeof_wchar_t = sizeof(wchar_t);
sizeof_size_t = sizeof(std::size_t); sizeof_size_t = sizeof(std::size_t);
sizeof_pointer = sizeof(void *); sizeof_pointer = sizeof(void *);
return true; return true;
@ -161,6 +162,7 @@ bool Settings::platform(PlatformType type)
sizeof_float = 4; sizeof_float = 4;
sizeof_double = 8; sizeof_double = 8;
sizeof_long_double = 8; sizeof_long_double = 8;
sizeof_wchar_t = 2;
sizeof_size_t = 4; sizeof_size_t = 4;
sizeof_pointer = 4; sizeof_pointer = 4;
return true; return true;
@ -174,6 +176,7 @@ bool Settings::platform(PlatformType type)
sizeof_float = 4; sizeof_float = 4;
sizeof_double = 8; sizeof_double = 8;
sizeof_long_double = 8; sizeof_long_double = 8;
sizeof_wchar_t = 2;
sizeof_size_t = 8; sizeof_size_t = 8;
sizeof_pointer = 8; sizeof_pointer = 8;
return true; return true;
@ -187,6 +190,7 @@ bool Settings::platform(PlatformType type)
sizeof_float = 4; sizeof_float = 4;
sizeof_double = 8; sizeof_double = 8;
sizeof_long_double = 12; sizeof_long_double = 12;
sizeof_wchar_t = 4;
sizeof_size_t = 4; sizeof_size_t = 4;
sizeof_pointer = 4; sizeof_pointer = 4;
return true; return true;
@ -200,6 +204,7 @@ bool Settings::platform(PlatformType type)
sizeof_float = 4; sizeof_float = 4;
sizeof_double = 8; sizeof_double = 8;
sizeof_long_double = 16; sizeof_long_double = 16;
sizeof_wchar_t = 4;
sizeof_size_t = 8; sizeof_size_t = 8;
sizeof_pointer = 8; sizeof_pointer = 8;
return true; return true;

View File

@ -205,6 +205,7 @@ public:
unsigned int sizeof_float; unsigned int sizeof_float;
unsigned int sizeof_double; unsigned int sizeof_double;
unsigned int sizeof_long_double; unsigned int sizeof_long_double;
unsigned int sizeof_wchar_t;
unsigned int sizeof_size_t; unsigned int sizeof_size_t;
unsigned int sizeof_pointer; unsigned int sizeof_pointer;

View File

@ -1569,6 +1569,7 @@ bool Tokenizer::tokenize(std::istream &code,
_typeSize["long"] = _settings->sizeof_long; _typeSize["long"] = _settings->sizeof_long;
_typeSize["float"] = _settings->sizeof_float; _typeSize["float"] = _settings->sizeof_float;
_typeSize["double"] = _settings->sizeof_double; _typeSize["double"] = _settings->sizeof_double;
_typeSize["wchar_t"] = _settings->sizeof_wchar_t;
_typeSize["size_t"] = _settings->sizeof_size_t; _typeSize["size_t"] = _settings->sizeof_size_t;
_typeSize["*"] = _settings->sizeof_pointer; _typeSize["*"] = _settings->sizeof_pointer;

View File

@ -446,6 +446,7 @@ private:
// a = b = 0; // a = b = 0;
TEST_CASE(multipleAssignment); TEST_CASE(multipleAssignment);
TEST_CASE(platformWin);
TEST_CASE(platformWin32); TEST_CASE(platformWin32);
TEST_CASE(platformWin32A); TEST_CASE(platformWin32A);
TEST_CASE(platformWin32W); TEST_CASE(platformWin32W);
@ -7011,27 +7012,8 @@ private:
ASSERT_EQUALS("a = b = 0 ;", tokenizeAndStringify("a=b=0;")); ASSERT_EQUALS("a = b = 0 ;", tokenizeAndStringify("a=b=0;"));
} }
void platformWin32() { void platformWin() {
const char code[] = "unsigned int sizeof_short = sizeof(short);" const char code[] = "BOOL f;"
"unsigned int sizeof_unsigned_short = sizeof(unsigned short);"
"unsigned int sizeof_int = sizeof(int);"
"unsigned int sizeof_unsigned_int = sizeof(unsigned int);"
"unsigned int sizeof_long = sizeof(long);"
"unsigned int sizeof_unsigned_long = sizeof(unsigned long);"
"unsigned int sizeof_long_long = sizeof(long long);"
"unsigned int sizeof_unsigned_long_long = sizeof(unsigned long long);"
"unsigned int sizeof_float = sizeof(float);"
"unsigned int sizeof_double = sizeof(double);"
"unsigned int sizeof_long_double = sizeof(long double);"
"unsigned int sizeof_bool = sizeof(bool);"
"unsigned int sizeof_pointer = sizeof(void *);"
"unsigned int sizeof_size_t = sizeof(size_t);"
"size_t a;"
"ssize_t b;"
"ptrdiff_t c;"
"intptr_t d;"
"uintptr_t e;"
"BOOL f;"
"BOOLEAN g;" "BOOLEAN g;"
"BYTE h;" "BYTE h;"
"CHAR i;" "CHAR i;"
@ -7066,12 +7048,6 @@ private:
"PCHAR L;" "PCHAR L;"
"LPVOID M;" "LPVOID M;"
"PVOID N;" "PVOID N;"
"DWORD_PTR O;"
"ULONG_PTR P;"
"SIZE_T Q;"
"HRESULT R;"
"LONG_PTR S;"
"HANDLE T;"
"BOOL _bool;" "BOOL _bool;"
"HFILE hfile;" "HFILE hfile;"
"LONG32 long32;" "LONG32 long32;"
@ -7079,7 +7055,6 @@ private:
"LCTYPE lctype;" "LCTYPE lctype;"
"LGRPID lgrpid;" "LGRPID lgrpid;"
"LONG64 long64;" "LONG64 long64;"
"SSIZE_T _ssize_t;"
"PUCHAR puchar;" "PUCHAR puchar;"
"LPCOLORREF lpcolorref;" "LPCOLORREF lpcolorref;"
"PDWORD pdword;" "PDWORD pdword;"
@ -7102,36 +7077,13 @@ private:
"HWINSTA hwinsta;" "HWINSTA hwinsta;"
"PWCHAR pwchar;" "PWCHAR pwchar;"
"PUSHORT pushort;" "PUSHORT pushort;"
"UINT_PTR uint_ptr;"
"WPARAM wparam;"
"LANGID langid;" "LANGID langid;"
"DWORD64 dword64;" "DWORD64 dword64;"
"ULONG64 ulong64;" "ULONG64 ulong64;"
"HALF_PTR half_ptr;"
"INT_PTR int_ptr;"
"LPWSTR lpcwstr;" "LPWSTR lpcwstr;"
"LPCWSTR lpcwstr;"; "LPCWSTR lpcwstr;";
const char expected[] = "unsigned int sizeof_short ; sizeof_short = 2 ; " const char expected[] = "int f ; "
"unsigned int sizeof_unsigned_short ; sizeof_unsigned_short = 2 ; "
"unsigned int sizeof_int ; sizeof_int = 4 ; "
"unsigned int sizeof_unsigned_int ; sizeof_unsigned_int = 4 ; "
"unsigned int sizeof_long ; sizeof_long = 4 ; "
"unsigned int sizeof_unsigned_long ; sizeof_unsigned_long = 4 ; "
"unsigned int sizeof_long_long ; sizeof_long_long = 8 ; "
"unsigned int sizeof_unsigned_long_long ; sizeof_unsigned_long_long = 8 ; "
"unsigned int sizeof_float ; sizeof_float = 4 ; "
"unsigned int sizeof_double ; sizeof_double = 8 ; "
"unsigned int sizeof_long_double ; sizeof_long_double = 8 ; "
"unsigned int sizeof_bool ; sizeof_bool = 1 ; "
"unsigned int sizeof_pointer ; sizeof_pointer = 4 ; "
"unsigned int sizeof_size_t ; sizeof_size_t = 4 ; "
"unsigned long a ; "
"long b ; "
"long c ; "
"long d ; "
"unsigned long e ; "
"int f ; "
"unsigned char g ; " "unsigned char g ; "
"unsigned char h ; " "unsigned char h ; "
"char i ; " "char i ; "
@ -7166,12 +7118,6 @@ private:
"char * L ; " "char * L ; "
"void * M ; " "void * M ; "
"void * N ; " "void * N ; "
"unsigned long O ; "
"unsigned long P ; "
"unsigned long Q ; "
"long R ; "
"long S ; "
"void * T ; "
"int _bool ; " "int _bool ; "
"int hfile ; " "int hfile ; "
"int long32 ; " "int long32 ; "
@ -7179,7 +7125,6 @@ private:
"unsigned long lctype ; " "unsigned long lctype ; "
"unsigned long lgrpid ; " "unsigned long lgrpid ; "
"long long long64 ; " "long long long64 ; "
"long _ssize_t ; "
"unsigned char * puchar ; " "unsigned char * puchar ; "
"unsigned long * lpcolorref ; " "unsigned long * lpcolorref ; "
"unsigned long * pdword ; " "unsigned long * pdword ; "
@ -7202,16 +7147,86 @@ private:
"void * hwinsta ; " "void * hwinsta ; "
"wchar_t * pwchar ; " "wchar_t * pwchar ; "
"unsigned short * pushort ; " "unsigned short * pushort ; "
"unsigned int uint_ptr ; "
"unsigned int wparam ; "
"unsigned short langid ; " "unsigned short langid ; "
"unsigned long dword64 ; " "unsigned long dword64 ; "
"unsigned long ulong64 ; " "unsigned long ulong64 ; "
"short half_ptr ; "
"int int_ptr ; "
"wchar_t * lpcwstr ; " "wchar_t * lpcwstr ; "
"const wchar_t * lpcwstr ;"; "const wchar_t * lpcwstr ;";
// These types should be defined the same on all Windows platforms
std::string win32A = tokenizeAndStringify(code, true, true, Settings::Win32A);
ASSERT_EQUALS(expected, win32A);
ASSERT_EQUALS(win32A, tokenizeAndStringify(code, true, true, Settings::Win32W));
ASSERT_EQUALS(win32A, tokenizeAndStringify(code, true, true, Settings::Win64));
}
void platformWin32() {
const char code[] = "unsigned int sizeof_short = sizeof(short);"
"unsigned int sizeof_unsigned_short = sizeof(unsigned short);"
"unsigned int sizeof_int = sizeof(int);"
"unsigned int sizeof_unsigned_int = sizeof(unsigned int);"
"unsigned int sizeof_long = sizeof(long);"
"unsigned int sizeof_unsigned_long = sizeof(unsigned long);"
"unsigned int sizeof_long_long = sizeof(long long);"
"unsigned int sizeof_unsigned_long_long = sizeof(unsigned long long);"
"unsigned int sizeof_float = sizeof(float);"
"unsigned int sizeof_double = sizeof(double);"
"unsigned int sizeof_long_double = sizeof(long double);"
"unsigned int sizeof_bool = sizeof(bool);"
"unsigned int sizeof_wchar_t = sizeof(wchar_t);"
"unsigned int sizeof_pointer = sizeof(void *);"
"unsigned int sizeof_size_t = sizeof(size_t);"
"size_t a;"
"ssize_t b;"
"ptrdiff_t c;"
"intptr_t d;"
"uintptr_t e;"
"DWORD_PTR O;"
"ULONG_PTR P;"
"SIZE_T Q;"
"HRESULT R;"
"LONG_PTR S;"
"HANDLE T;"
"PHANDLE U;"
"SSIZE_T _ssize_t;"
"UINT_PTR uint_ptr;"
"WPARAM wparam;"
"HALF_PTR half_ptr;"
"INT_PTR int_ptr;";;
const char expected[] = "unsigned int sizeof_short ; sizeof_short = 2 ; "
"unsigned int sizeof_unsigned_short ; sizeof_unsigned_short = 2 ; "
"unsigned int sizeof_int ; sizeof_int = 4 ; "
"unsigned int sizeof_unsigned_int ; sizeof_unsigned_int = 4 ; "
"unsigned int sizeof_long ; sizeof_long = 4 ; "
"unsigned int sizeof_unsigned_long ; sizeof_unsigned_long = 4 ; "
"unsigned int sizeof_long_long ; sizeof_long_long = 8 ; "
"unsigned int sizeof_unsigned_long_long ; sizeof_unsigned_long_long = 8 ; "
"unsigned int sizeof_float ; sizeof_float = 4 ; "
"unsigned int sizeof_double ; sizeof_double = 8 ; "
"unsigned int sizeof_long_double ; sizeof_long_double = 8 ; "
"unsigned int sizeof_bool ; sizeof_bool = 1 ; "
"unsigned int sizeof_wchar_t ; sizeof_wchar_t = 2 ; "
"unsigned int sizeof_pointer ; sizeof_pointer = 4 ; "
"unsigned int sizeof_size_t ; sizeof_size_t = 4 ; "
"unsigned long a ; "
"long b ; "
"long c ; "
"long d ; "
"unsigned long e ; "
"unsigned long O ; "
"unsigned long P ; "
"unsigned long Q ; "
"long R ; "
"long S ; "
"void * T ; "
"void * * U ; "
"long _ssize_t ; "
"unsigned int uint_ptr ; "
"unsigned int wparam ; "
"short half_ptr ; "
"int int_ptr ;";
// These types should be defined the same on all Win32 platforms // These types should be defined the same on all Win32 platforms
std::string win32A = tokenizeAndStringify(code, true, true, Settings::Win32A); std::string win32A = tokenizeAndStringify(code, true, true, Settings::Win32A);
ASSERT_EQUALS(expected, win32A); ASSERT_EQUALS(expected, win32A);
@ -7323,6 +7338,7 @@ private:
"unsigned int sizeof_double = sizeof(double);" "unsigned int sizeof_double = sizeof(double);"
"unsigned int sizeof_long_double = sizeof(long double);" "unsigned int sizeof_long_double = sizeof(long double);"
"unsigned int sizeof_bool = sizeof(bool);" "unsigned int sizeof_bool = sizeof(bool);"
"unsigned int sizeof_wchar_t = sizeof(wchar_t);"
"unsigned int sizeof_pointer = sizeof(void *);" "unsigned int sizeof_pointer = sizeof(void *);"
"unsigned int sizeof_size_t = sizeof(size_t);" "unsigned int sizeof_size_t = sizeof(size_t);"
"size_t a;" "size_t a;"
@ -7355,6 +7371,7 @@ private:
"unsigned int sizeof_double ; sizeof_double = 8 ; " "unsigned int sizeof_double ; sizeof_double = 8 ; "
"unsigned int sizeof_long_double ; sizeof_long_double = 8 ; " "unsigned int sizeof_long_double ; sizeof_long_double = 8 ; "
"unsigned int sizeof_bool ; sizeof_bool = 1 ; " "unsigned int sizeof_bool ; sizeof_bool = 1 ; "
"unsigned int sizeof_wchar_t ; sizeof_wchar_t = 2 ; "
"unsigned int sizeof_pointer ; sizeof_pointer = 8 ; " "unsigned int sizeof_pointer ; sizeof_pointer = 8 ; "
"unsigned int sizeof_size_t ; sizeof_size_t = 8 ; " "unsigned int sizeof_size_t ; sizeof_size_t = 8 ; "
"unsigned long long a ; " "unsigned long long a ; "
@ -7391,6 +7408,7 @@ private:
"unsigned int sizeof_double = sizeof(double);" "unsigned int sizeof_double = sizeof(double);"
"unsigned int sizeof_long_double = sizeof(long double);" "unsigned int sizeof_long_double = sizeof(long double);"
"unsigned int sizeof_bool = sizeof(bool);" "unsigned int sizeof_bool = sizeof(bool);"
"unsigned int sizeof_wchar_t = sizeof(wchar_t);"
"unsigned int sizeof_pointer = sizeof(void *);" "unsigned int sizeof_pointer = sizeof(void *);"
"unsigned int sizeof_size_t = sizeof(size_t);" "unsigned int sizeof_size_t = sizeof(size_t);"
"size_t a;" "size_t a;"
@ -7411,6 +7429,7 @@ private:
"unsigned int sizeof_double ; sizeof_double = 8 ; " "unsigned int sizeof_double ; sizeof_double = 8 ; "
"unsigned int sizeof_long_double ; sizeof_long_double = 12 ; " "unsigned int sizeof_long_double ; sizeof_long_double = 12 ; "
"unsigned int sizeof_bool ; sizeof_bool = 1 ; " "unsigned int sizeof_bool ; sizeof_bool = 1 ; "
"unsigned int sizeof_wchar_t ; sizeof_wchar_t = 4 ; "
"unsigned int sizeof_pointer ; sizeof_pointer = 4 ; " "unsigned int sizeof_pointer ; sizeof_pointer = 4 ; "
"unsigned int sizeof_size_t ; sizeof_size_t = 4 ; " "unsigned int sizeof_size_t ; sizeof_size_t = 4 ; "
"unsigned long a ; " "unsigned long a ; "
@ -7435,6 +7454,7 @@ private:
"unsigned int sizeof_double = sizeof(double);" "unsigned int sizeof_double = sizeof(double);"
"unsigned int sizeof_long_double = sizeof(long double);" "unsigned int sizeof_long_double = sizeof(long double);"
"unsigned int sizeof_bool = sizeof(bool);" "unsigned int sizeof_bool = sizeof(bool);"
"unsigned int sizeof_wchar_t = sizeof(wchar_t);"
"unsigned int sizeof_pointer = sizeof(void *);" "unsigned int sizeof_pointer = sizeof(void *);"
"unsigned int sizeof_size_t = sizeof(size_t);" "unsigned int sizeof_size_t = sizeof(size_t);"
"size_t a;" "size_t a;"
@ -7455,6 +7475,7 @@ private:
"unsigned int sizeof_double ; sizeof_double = 8 ; " "unsigned int sizeof_double ; sizeof_double = 8 ; "
"unsigned int sizeof_long_double ; sizeof_long_double = 16 ; " "unsigned int sizeof_long_double ; sizeof_long_double = 16 ; "
"unsigned int sizeof_bool ; sizeof_bool = 1 ; " "unsigned int sizeof_bool ; sizeof_bool = 1 ; "
"unsigned int sizeof_wchar_t ; sizeof_wchar_t = 4 ; "
"unsigned int sizeof_pointer ; sizeof_pointer = 8 ; " "unsigned int sizeof_pointer ; sizeof_pointer = 8 ; "
"unsigned int sizeof_size_t ; sizeof_size_t = 8 ; " "unsigned int sizeof_size_t ; sizeof_size_t = 8 ; "
"unsigned long long a ; " "unsigned long long a ; "