Skip to content

Commit e69b368

Browse files
committed
extracted hard-coded platform definitions for unix32, unix64, win32A, win32W and win64 to actual platform files
1 parent de9795b commit e69b368

8 files changed

Lines changed: 177 additions & 99 deletions

File tree

lib/platform.cpp

Lines changed: 52 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -70,86 +70,14 @@ bool cppcheck::Platform::set(Type t)
7070
return true;
7171
case Type::Win32W:
7272
case Type::Win32A:
73-
type = t;
74-
sizeof_bool = 1; // 4 in Visual C++ 4.2
75-
sizeof_short = 2;
76-
sizeof_int = 4;
77-
sizeof_long = 4;
78-
sizeof_long_long = 8;
79-
sizeof_float = 4;
80-
sizeof_double = 8;
81-
sizeof_long_double = 8;
82-
sizeof_wchar_t = 2;
83-
sizeof_size_t = 4;
84-
sizeof_pointer = 4;
85-
defaultSign = '\0';
86-
char_bit = 8;
87-
short_bit = char_bit * sizeof_short;
88-
int_bit = char_bit * sizeof_int;
89-
long_bit = char_bit * sizeof_long;
90-
long_long_bit = char_bit * sizeof_long_long;
91-
return true;
9273
case Type::Win64:
93-
type = t;
94-
sizeof_bool = 1;
95-
sizeof_short = 2;
96-
sizeof_int = 4;
97-
sizeof_long = 4;
98-
sizeof_long_long = 8;
99-
sizeof_float = 4;
100-
sizeof_double = 8;
101-
sizeof_long_double = 8;
102-
sizeof_wchar_t = 2;
103-
sizeof_size_t = 8;
104-
sizeof_pointer = 8;
105-
defaultSign = '\0';
106-
char_bit = 8;
107-
short_bit = char_bit * sizeof_short;
108-
int_bit = char_bit * sizeof_int;
109-
long_bit = char_bit * sizeof_long;
110-
long_long_bit = char_bit * sizeof_long_long;
111-
return true;
11274
case Type::Unix32:
113-
type = t;
114-
sizeof_bool = 1;
115-
sizeof_short = 2;
116-
sizeof_int = 4;
117-
sizeof_long = 4;
118-
sizeof_long_long = 8;
119-
sizeof_float = 4;
120-
sizeof_double = 8;
121-
sizeof_long_double = 12;
122-
sizeof_wchar_t = 4;
123-
sizeof_size_t = 4;
124-
sizeof_pointer = 4;
125-
defaultSign = '\0';
126-
char_bit = 8;
127-
short_bit = char_bit * sizeof_short;
128-
int_bit = char_bit * sizeof_int;
129-
long_bit = char_bit * sizeof_long;
130-
long_long_bit = char_bit * sizeof_long_long;
131-
return true;
13275
case Type::Unix64:
13376
type = t;
134-
sizeof_bool = 1;
135-
sizeof_short = 2;
136-
sizeof_int = 4;
137-
sizeof_long = 8;
138-
sizeof_long_long = 8;
139-
sizeof_float = 4;
140-
sizeof_double = 8;
141-
sizeof_long_double = 16;
142-
sizeof_wchar_t = 4;
143-
sizeof_size_t = 8;
144-
sizeof_pointer = 8;
145-
defaultSign = '\0';
146-
char_bit = 8;
147-
short_bit = char_bit * sizeof_short;
148-
int_bit = char_bit * sizeof_int;
149-
long_bit = char_bit * sizeof_long;
150-
long_long_bit = char_bit * sizeof_long_long;
77+
// read from platform file
15178
return true;
15279
case Type::File:
80+
type = t;
15381
// sizes are not set.
15482
return false;
15583
}
@@ -159,40 +87,73 @@ bool cppcheck::Platform::set(Type t)
15987

16088
bool cppcheck::Platform::set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool verbose)
16189
{
162-
if (platformstr == "win32A")
163-
set(Type::Win32A);
164-
else if (platformstr == "win32W")
165-
set(Type::Win32W);
166-
else if (platformstr == "win64")
167-
set(Type::Win64);
168-
else if (platformstr == "unix32")
169-
set(Type::Unix32);
170-
else if (platformstr == "unix64")
171-
set(Type::Unix64);
172-
else if (platformstr == "native")
173-
set(Type::Native);
174-
else if (platformstr == "unspecified")
175-
set(Type::Unspecified);
90+
Type t;
91+
std::string platformFile;
92+
93+
if (platformstr == "win32A") {
94+
// TODO: deprecate
95+
//std::cout << "Platform 'win32A' is deprecated and will be removed in a future version. Please use 'win32a' instead." << std::endl;
96+
t = Type::Win32A;
97+
platformFile = "win32a";
98+
}
99+
else if (platformstr == "win32a") {
100+
t = Type::Win32A;
101+
platformFile = platformstr;
102+
}
103+
else if (platformstr == "win32W") {
104+
// TODO: deprecate
105+
//std::cout << "Platform 'win32W' is deprecated and will be removed in a future version. Please use 'win32w' instead." << std::endl;
106+
t = Type::Win32W;
107+
platformFile = "win32w";
108+
}
109+
else if (platformstr == "win32w") {
110+
t = Type::Win32W;
111+
platformFile = platformstr;
112+
}
113+
else if (platformstr == "win64") {
114+
t = Type::Win64;
115+
platformFile = platformstr;
116+
}
117+
else if (platformstr == "unix32") {
118+
t = Type::Unix32;
119+
platformFile = platformstr;
120+
}
121+
else if (platformstr == "unix64") {
122+
t = Type::Unix64;
123+
platformFile = platformstr;
124+
}
125+
else if (platformstr == "native") {
126+
t = Type::Native;
127+
}
128+
else if (platformstr == "unspecified") {
129+
t = Type::Unspecified;
130+
}
176131
else if (paths.empty()) {
177132
errstr = "unrecognized platform: '" + platformstr + "' (no lookup).";
178133
return false;
179134
}
180135
else {
136+
t = Type::File;
137+
platformFile = platformstr;
138+
}
139+
140+
if (!platformFile.empty()) {
181141
bool found = false;
182142
for (const std::string& path : paths) {
183143
if (verbose)
184-
std::cout << "looking for platform '" + platformstr + "' in '" + path + "'" << std::endl;
185-
if (loadFromFile(path.c_str(), platformstr, verbose)) {
144+
std::cout << "looking for platform '" + platformFile + "' in '" + path + "'" << std::endl;
145+
if (loadFromFile(path.c_str(), platformFile, verbose)) {
186146
found = true;
187147
break;
188148
}
189149
}
190150
if (!found) {
191-
errstr = "unrecognized platform: '" + platformstr + "'.";
151+
errstr = "unrecognized platform: '" + platformFile + "'.";
192152
return false;
193153
}
194154
}
195155

156+
set(t);
196157
return true;
197158
}
198159

@@ -297,6 +258,5 @@ bool cppcheck::Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc)
297258
long_bit = char_bit * sizeof_long;
298259
long_long_bit = char_bit * sizeof_long_long;
299260

300-
type = Type::File;
301261
return !error;
302262
}

platforms/unix32.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<platform>
3+
<char_bit>8</char_bit>
4+
<default-sign>&#x000;</default-sign>
5+
<sizeof>
6+
<bool>1</bool>
7+
<short>2</short>
8+
<int>4</int>
9+
<long>4</long>
10+
<long-long>8</long-long>
11+
<float>4</float>
12+
<double>8</double>
13+
<long-double>12</long-double>
14+
<pointer>4</pointer>
15+
<size_t>4</size_t>
16+
<wchar_t>4</wchar_t>
17+
</sizeof>
18+
</platform>

platforms/unix64.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<platform>
3+
<char_bit>8</char_bit>
4+
<default-sign>&#x000;</default-sign>
5+
<sizeof>
6+
<bool>1</bool>
7+
<short>2</short>
8+
<int>4</int>
9+
<long>8</long>
10+
<long-long>8</long-long>
11+
<float>4</float>
12+
<double>8</double>
13+
<long-double>16</long-double>
14+
<pointer>8</pointer>
15+
<size_t>8</size_t>
16+
<wchar_t>4</wchar_t>
17+
</sizeof>
18+
</platform>

platforms/win32a.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<platform>
3+
<char_bit>8</char_bit>
4+
<default-sign>&#x000;</default-sign>
5+
<sizeof>
6+
<bool>1</bool><!--4 in Visual C++ 4.2-->
7+
<short>2</short>
8+
<int>4</int>
9+
<long>4</long>
10+
<long-long>8</long-long>
11+
<float>4</float>
12+
<double>8</double>
13+
<long-double>8</long-double>
14+
<pointer>4</pointer>
15+
<size_t>4</size_t>
16+
<wchar_t>2</wchar_t>
17+
</sizeof>
18+
</platform>

platforms/win32w.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<platform>
3+
<char_bit>8</char_bit>
4+
<default-sign>&#x000;</default-sign>
5+
<sizeof>
6+
<bool>1</bool><!--4 in Visual C++ 4.2-->
7+
<short>2</short>
8+
<int>4</int>
9+
<long>4</long>
10+
<long-long>8</long-long>
11+
<float>4</float>
12+
<double>8</double>
13+
<long-double>8</long-double>
14+
<pointer>4</pointer>
15+
<size_t>4</size_t>
16+
<wchar_t>2</wchar_t>
17+
</sizeof>
18+
</platform>

platforms/win64.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<platform>
3+
<char_bit>8</char_bit>
4+
<default-sign>&#x000;</default-sign>
5+
<sizeof>
6+
<bool>1</bool>
7+
<short>2</short>
8+
<int>4</int>
9+
<long>4</long>
10+
<long-long>8</long-long>
11+
<float>4</float>
12+
<double>8</double>
13+
<long-double>8</long-double>
14+
<pointer>8</pointer>
15+
<size_t>8</size_t>
16+
<wchar_t>2</wchar_t>
17+
</sizeof>
18+
</platform>

test/testcmdlineparser.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ class TestCmdlineParser : public TestFixture {
138138
TEST_CASE(stdunknown);
139139
TEST_CASE(platformWin64);
140140
TEST_CASE(platformWin32A);
141+
TEST_CASE(platformWin32a);
141142
TEST_CASE(platformWin32W);
143+
TEST_CASE(platformWin32w);
142144
TEST_CASE(platformUnix32);
143145
TEST_CASE(platformUnix32Unsigned);
144146
TEST_CASE(platformUnix64);
@@ -1086,6 +1088,16 @@ class TestCmdlineParser : public TestFixture {
10861088
ASSERT(defParser.parseFromArgs(3, argv));
10871089
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings.platform.type);
10881090
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1091+
//ASSERT_EQUALS("Platform 'win32A' is deprecated and will be removed in a future version. Please use 'win32a' instead.\n", GET_REDIRECT_OUTPUT);
1092+
}
1093+
1094+
void platformWin32a() {
1095+
REDIRECT;
1096+
const char * const argv[] = {"cppcheck", "--platform=win32a", "file.cpp"};
1097+
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
1098+
ASSERT(defParser.parseFromArgs(3, argv));
1099+
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings.platform.type);
1100+
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
10891101
}
10901102

10911103
void platformWin32W() {
@@ -1095,6 +1107,16 @@ class TestCmdlineParser : public TestFixture {
10951107
ASSERT(defParser.parseFromArgs(3, argv));
10961108
ASSERT_EQUALS(cppcheck::Platform::Type::Win32W, settings.platform.type);
10971109
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1110+
//ASSERT_EQUALS("Platform 'win32W' is deprecated and will be removed in a future version. Please use 'win32w' instead.\n", GET_REDIRECT_OUTPUT);
1111+
}
1112+
1113+
void platformWin32w() {
1114+
REDIRECT;
1115+
const char * const argv[] = {"cppcheck", "--platform=win32w", "file.cpp"};
1116+
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
1117+
ASSERT(defParser.parseFromArgs(3, argv));
1118+
ASSERT_EQUALS(cppcheck::Platform::Type::Win32W, settings.platform.type);
1119+
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
10981120
}
10991121

11001122
void platformUnix32() {
@@ -1181,7 +1203,7 @@ class TestCmdlineParser : public TestFixture {
11811203
ASSERT_EQUALS("cppcheck: Windows 64-bit binaries currently default to the 'win64' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win64' explicitly if you rely on this.\n", GET_REDIRECT_OUTPUT);
11821204
#elif defined(_WIN32)
11831205
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings.platform.type);
1184-
ASSERT_EQUALS("cppcheck: Windows 32-bit binaries currently default to the 'win32A' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win32A' explicitly if you rely on this.\n", GET_REDIRECT_OUTPUT);
1206+
ASSERT_EQUALS("cppcheck: Windows 32-bit binaries currently default to the 'win32a' platform. Starting with Cppcheck 2.13 they will default to 'native' instead. Please specify '--platform=win32a' explicitly if you rely on this.\n", GET_REDIRECT_OUTPUT);
11851207
#endif
11861208

11871209
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;

test/testplatform.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ class TestPlatform : public TestFixture {
204204
" </platform>";
205205
cppcheck::Platform platform;
206206
ASSERT(readPlatform(platform, xmldata));
207-
ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
208-
ASSERT(!platform.isWindows());
207+
// not set by code
208+
// ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
209+
// ASSERT(!platform.isWindows());
209210
ASSERT_EQUALS(8, platform.char_bit);
210211
ASSERT_EQUALS('u', platform.defaultSign);
211212
ASSERT_EQUALS(1, platform.sizeof_bool);
@@ -248,8 +249,9 @@ class TestPlatform : public TestFixture {
248249
" </platform>";
249250
cppcheck::Platform platform;
250251
ASSERT(readPlatform(platform, xmldata));
251-
ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
252-
ASSERT(!platform.isWindows());
252+
// not set by code
253+
// ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
254+
// ASSERT(!platform.isWindows());
253255
ASSERT_EQUALS(20, platform.char_bit);
254256
ASSERT_EQUALS('s', platform.defaultSign);
255257
ASSERT_EQUALS(1, platform.sizeof_bool);
@@ -318,8 +320,9 @@ class TestPlatform : public TestFixture {
318320
" </platform>";
319321
cppcheck::Platform platform;
320322
ASSERT(readPlatform(platform, xmldata));
321-
ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
322-
ASSERT(!platform.isWindows());
323+
// not set by the code
324+
// ASSERT_EQUALS(cppcheck::Platform::Type::File, platform.type);
325+
// ASSERT(!platform.isWindows());
323326
ASSERT_EQUALS(0, platform.char_bit);
324327
ASSERT_EQUALS('z', platform.defaultSign);
325328
ASSERT_EQUALS(0, platform.sizeof_bool);
@@ -386,6 +389,9 @@ class TestPlatform : public TestFixture {
386389
" </platform>";
387390
cppcheck::Platform platform;
388391
ASSERT(!readPlatform(platform, xmldata));
392+
// not set by code
393+
//ASSERT_EQUALS(cppcheck::Platform::Win64, platform.platformType);
394+
//ASSERT(platform.isWindowsPlatform());
389395
}
390396

391397
void default_platform() {

0 commit comments

Comments
 (0)