Skip to content

Commit c2c7473

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

8 files changed

Lines changed: 176 additions & 98 deletions

File tree

lib/platform.cpp

Lines changed: 52 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -63,86 +63,14 @@ bool cppcheck::Platform::set(Type t)
6363
return true;
6464
case Type::Win32W:
6565
case Type::Win32A:
66-
type = t;
67-
sizeof_bool = 1; // 4 in Visual C++ 4.2
68-
sizeof_short = 2;
69-
sizeof_int = 4;
70-
sizeof_long = 4;
71-
sizeof_long_long = 8;
72-
sizeof_float = 4;
73-
sizeof_double = 8;
74-
sizeof_long_double = 8;
75-
sizeof_wchar_t = 2;
76-
sizeof_size_t = 4;
77-
sizeof_pointer = 4;
78-
defaultSign = '\0';
79-
char_bit = 8;
80-
short_bit = char_bit * sizeof_short;
81-
int_bit = char_bit * sizeof_int;
82-
long_bit = char_bit * sizeof_long;
83-
long_long_bit = char_bit * sizeof_long_long;
84-
return true;
8566
case Type::Win64:
86-
type = t;
87-
sizeof_bool = 1;
88-
sizeof_short = 2;
89-
sizeof_int = 4;
90-
sizeof_long = 4;
91-
sizeof_long_long = 8;
92-
sizeof_float = 4;
93-
sizeof_double = 8;
94-
sizeof_long_double = 8;
95-
sizeof_wchar_t = 2;
96-
sizeof_size_t = 8;
97-
sizeof_pointer = 8;
98-
defaultSign = '\0';
99-
char_bit = 8;
100-
short_bit = char_bit * sizeof_short;
101-
int_bit = char_bit * sizeof_int;
102-
long_bit = char_bit * sizeof_long;
103-
long_long_bit = char_bit * sizeof_long_long;
104-
return true;
10567
case Type::Unix32:
106-
type = t;
107-
sizeof_bool = 1;
108-
sizeof_short = 2;
109-
sizeof_int = 4;
110-
sizeof_long = 4;
111-
sizeof_long_long = 8;
112-
sizeof_float = 4;
113-
sizeof_double = 8;
114-
sizeof_long_double = 12;
115-
sizeof_wchar_t = 4;
116-
sizeof_size_t = 4;
117-
sizeof_pointer = 4;
118-
defaultSign = '\0';
119-
char_bit = 8;
120-
short_bit = char_bit * sizeof_short;
121-
int_bit = char_bit * sizeof_int;
122-
long_bit = char_bit * sizeof_long;
123-
long_long_bit = char_bit * sizeof_long_long;
124-
return true;
12568
case Type::Unix64:
12669
type = t;
127-
sizeof_bool = 1;
128-
sizeof_short = 2;
129-
sizeof_int = 4;
130-
sizeof_long = 8;
131-
sizeof_long_long = 8;
132-
sizeof_float = 4;
133-
sizeof_double = 8;
134-
sizeof_long_double = 16;
135-
sizeof_wchar_t = 4;
136-
sizeof_size_t = 8;
137-
sizeof_pointer = 8;
138-
defaultSign = '\0';
139-
char_bit = 8;
140-
short_bit = char_bit * sizeof_short;
141-
int_bit = char_bit * sizeof_int;
142-
long_bit = char_bit * sizeof_long;
143-
long_long_bit = char_bit * sizeof_long_long;
70+
// read from platform file
14471
return true;
14572
case Type::File:
73+
type = t;
14674
// sizes are not set.
14775
return false;
14876
}
@@ -152,40 +80,73 @@ bool cppcheck::Platform::set(Type t)
15280

15381
bool cppcheck::Platform::set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool verbose)
15482
{
155-
if (platformstr == "win32A")
156-
set(Type::Win32A);
157-
else if (platformstr == "win32W")
158-
set(Type::Win32W);
159-
else if (platformstr == "win64")
160-
set(Type::Win64);
161-
else if (platformstr == "unix32")
162-
set(Type::Unix32);
163-
else if (platformstr == "unix64")
164-
set(Type::Unix64);
165-
else if (platformstr == "native")
166-
set(Type::Native);
167-
else if (platformstr == "unspecified")
168-
set(Type::Unspecified);
83+
Type t;
84+
std::string platformFile;
85+
86+
if (platformstr == "win32A") {
87+
// TODO: deprecate
88+
//std::cout << "Platform 'win32A' is deprecated and will be removed in a future version. Please use 'win32a' instead." << std::endl;
89+
t = Type::Win32A;
90+
platformFile = "win32a";
91+
}
92+
else if (platformstr == "win32a") {
93+
t = Type::Win32A;
94+
platformFile = platformstr;
95+
}
96+
else if (platformstr == "win32W") {
97+
// TODO: deprecate
98+
//std::cout << "Platform 'win32W' is deprecated and will be removed in a future version. Please use 'win32w' instead." << std::endl;
99+
t = Type::Win32W;
100+
platformFile = "win32w";
101+
}
102+
else if (platformstr == "win32w") {
103+
t = Type::Win32W;
104+
platformFile = platformstr;
105+
}
106+
else if (platformstr == "win64") {
107+
t = Type::Win64;
108+
platformFile = platformstr;
109+
}
110+
else if (platformstr == "unix32") {
111+
t = Type::Unix32;
112+
platformFile = platformstr;
113+
}
114+
else if (platformstr == "unix64") {
115+
t = Type::Unix64;
116+
platformFile = platformstr;
117+
}
118+
else if (platformstr == "native") {
119+
t = Type::Native;
120+
}
121+
else if (platformstr == "unspecified") {
122+
t = Type::Unspecified;
123+
}
169124
else if (paths.empty()) {
170125
errstr = "unrecognized platform: '" + platformstr + "' (no lookup).";
171126
return false;
172127
}
173128
else {
129+
t = Type::File;
130+
platformFile = platformstr;
131+
}
132+
133+
if (!platformFile.empty()) {
174134
bool found = false;
175135
for (const std::string& path : paths) {
176136
if (verbose)
177-
std::cout << "looking for platform '" + platformstr + "' in '" + path + "'" << std::endl;
178-
if (loadFromFile(path.c_str(), platformstr, verbose)) {
137+
std::cout << "looking for platform '" + platformFile + "' in '" + path + "'" << std::endl;
138+
if (loadFromFile(path.c_str(), platformFile, verbose)) {
179139
found = true;
180140
break;
181141
}
182142
}
183143
if (!found) {
184-
errstr = "unrecognized platform: '" + platformstr + "'.";
144+
errstr = "unrecognized platform: '" + platformFile + "'.";
185145
return false;
186146
}
187147
}
188148

149+
set(t);
189150
return true;
190151
}
191152

@@ -290,6 +251,5 @@ bool cppcheck::Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc)
290251
long_bit = char_bit * sizeof_long;
291252
long_long_bit = char_bit * sizeof_long_long;
292253

293-
type = Type::File;
294254
return !error;
295255
}

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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ class TestCmdlineParser : public TestFixture {
150150
TEST_CASE(stdunknown2);
151151
TEST_CASE(platformWin64);
152152
TEST_CASE(platformWin32A);
153+
TEST_CASE(platformWin32a);
153154
TEST_CASE(platformWin32W);
155+
TEST_CASE(platformWin32w);
154156
TEST_CASE(platformUnix32);
155157
TEST_CASE(platformUnix32Unsigned);
156158
TEST_CASE(platformUnix64);
@@ -1142,6 +1144,16 @@ class TestCmdlineParser : public TestFixture {
11421144
ASSERT(parser->parseFromArgs(3, argv));
11431145
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings->platform.type);
11441146
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1147+
//ASSERT_EQUALS("Platform 'win32A' is deprecated and will be removed in a future version. Please use 'win32a' instead.\n", GET_REDIRECT_OUTPUT);
1148+
}
1149+
1150+
void platformWin32a() {
1151+
REDIRECT;
1152+
const char * const argv[] = {"cppcheck", "--platform=win32a", "file.cpp"};
1153+
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
1154+
ASSERT(defParser.parseFromArgs(3, argv));
1155+
ASSERT_EQUALS(cppcheck::Platform::Type::Win32A, settings.platform.type);
1156+
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
11451157
}
11461158

11471159
void platformWin32W() {
@@ -1151,6 +1163,16 @@ class TestCmdlineParser : public TestFixture {
11511163
ASSERT(parser->parseFromArgs(3, argv));
11521164
ASSERT_EQUALS(cppcheck::Platform::Type::Win32W, settings->platform.type);
11531165
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1166+
//ASSERT_EQUALS("Platform 'win32W' is deprecated and will be removed in a future version. Please use 'win32w' instead.\n", GET_REDIRECT_OUTPUT);
1167+
}
1168+
1169+
void platformWin32w() {
1170+
REDIRECT;
1171+
const char * const argv[] = {"cppcheck", "--platform=win32w", "file.cpp"};
1172+
ASSERT(settings.platform.set(cppcheck::Platform::Type::Unspecified));
1173+
ASSERT(defParser.parseFromArgs(3, argv));
1174+
ASSERT_EQUALS(cppcheck::Platform::Type::Win32W, settings.platform.type);
1175+
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
11541176
}
11551177

11561178
void platformUnix32() {

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() const {

0 commit comments

Comments
 (0)