From e234e8cc5be05c3410a0de7fa279631c4d5d12ec Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 19 Sep 2011 23:14:58 -0400 Subject: [PATCH] add some common windows pointer type conversions to standard types --- lib/tokenize.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++ test/testtokenize.cpp | 41 +++++++++++++++++++++++++++++--- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8a01edb68..da48935be 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6667,6 +6667,61 @@ void Tokenizer::simplifyPlatformTypes() } else if (tok->str() == "LONG") tok->str("long"); + else if (Token::Match(tok, "LPBOOL|PBOOL")) + { + tok->str("int"); + tok->insertToken("*"); + } + else if (Token::Match(tok, "LPBYTE|PBOOLEAN|PBYTE")) + { + tok->str("unsigned"); + tok->insertToken("*"); + tok->insertToken("char"); + } + else if (Token::Match(tok, "LPCSTR|PCSTR")) + { + tok->str("const"); + tok->insertToken("*"); + tok->insertToken("char"); + } + else if (tok->str() == "LPCVOID") + { + tok->str("const"); + tok->insertToken("*"); + tok->insertToken("void"); + } + else if (tok->str() == "LPDWORD") + { + tok->str("unsigned"); + tok->insertToken("*"); + tok->insertToken("long"); + } + else if (Token::Match(tok, "LPINT|PINT")) + { + tok->str("int"); + tok->insertToken("*"); + } + else if (Token::Match(tok, "LPLONG|PLONG")) + { + tok->str("long"); + tok->insertToken("*"); + } + else if (Token::Match(tok, "LPSTR|PSTR|PCHAR")) + { + tok->str("char"); + tok->insertToken("*"); + } + else if (Token::Match(tok, "LPVOID|PVOID")) + { + tok->str("void"); + tok->insertToken("*"); + } + else if (Token::Match(tok, "LPWORD|PWORD")) + { + tok->str("unsigned"); + tok->insertToken("*"); + tok->insertToken("short"); + } else if (tok->str() == "SHORT") tok->str("short"); else if (tok->str() == "UINT") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5f88f0384..082205d5f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5978,8 +5978,25 @@ private: "ULONG s;" "USHORT t;" "WORD u;" - "VOID * v;"; - + "VOID *v;" + "LPBOOL w;" + "PBOOL x;" + "LPBYTE y;" + "PBOOLEAN z;" + "PBYTE A;" + "LPCSTR B;" + "PCSTR C;" + "LPCVOID D;" + "LPDWORD E;" + "LPINT F;" + "PINT G;" + "LPLONG H;" + "PLONG I;" + "LPSTR J;" + "PSTR K;" + "PCHAR L;" + "LPVOID M;" + "PVOID N;"; const char expected[] = "unsigned int sizeof_short ; sizeof_short = 2 ; " "unsigned int sizeof_unsigned_short ; sizeof_unsigned_short = 2 ; " @@ -6016,7 +6033,25 @@ private: "unsigned long s ; " "unsigned short t ; " "unsigned short u ; " - "void * v ;"; + "void * v ; " + "int * w ; " + "int * x ; " + "unsigned char * y ; " + "unsigned char * z ; " + "unsigned char * A ; " + "const char * B ; " + "const char * C ; " + "const void * D ; " + "unsigned long * E ; " + "int * F ; " + "int * G ; " + "long * H ; " + "long * I ; " + "char * J ; " + "char * K ; " + "char * L ; " + "void * M ; " + "void * N ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Win32)); }