Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,14 +957,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mLogger.printError(errstr);
return Result::Fail;
}

// TODO: remove
// these are loaded via external files and thus have Settings::PlatformFile set instead.
// override the type so they behave like the regular platforms.
if (platform == "unix32-unsigned")
mSettings.platform.type = Platform::Type::Unix32;
else if (platform == "unix64-unsigned")
mSettings.platform.type = Platform::Type::Unix64;
}

// Write results in results.plist
Expand Down
170 changes: 72 additions & 98 deletions lib/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ bool Platform::set(Type t)
sizeof_wchar_t = sizeof(wchar_t);
sizeof_size_t = sizeof(std::size_t);
sizeof_pointer = sizeof(void *);
if (type == Type::Unspecified) {
defaultSign = '\0';
} else {
defaultSign = std::numeric_limits<char>::is_signed ? 's' : 'u';
}
defaultSign = std::numeric_limits<char>::is_signed ? 's' : 'u';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
Expand All @@ -63,86 +59,14 @@ bool Platform::set(Type t)
return true;
case Type::Win32W:
case Type::Win32A:
type = t;
sizeof_bool = 1; // 4 in Visual C++ 4.2
sizeof_short = 2;
sizeof_int = 4;
sizeof_long = 4;
sizeof_long_long = 8;
sizeof_float = 4;
sizeof_double = 8;
sizeof_long_double = 8;
sizeof_wchar_t = 2;
sizeof_size_t = 4;
sizeof_pointer = 4;
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
case Type::Win64:
type = t;
sizeof_bool = 1;
sizeof_short = 2;
sizeof_int = 4;
sizeof_long = 4;
sizeof_long_long = 8;
sizeof_float = 4;
sizeof_double = 8;
sizeof_long_double = 8;
sizeof_wchar_t = 2;
sizeof_size_t = 8;
sizeof_pointer = 8;
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
case Type::Unix32:
type = t;
sizeof_bool = 1;
sizeof_short = 2;
sizeof_int = 4;
sizeof_long = 4;
sizeof_long_long = 8;
sizeof_float = 4;
sizeof_double = 8;
sizeof_long_double = 12;
sizeof_wchar_t = 4;
sizeof_size_t = 4;
sizeof_pointer = 4;
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
return true;
case Type::Unix64:
type = t;
sizeof_bool = 1;
sizeof_short = 2;
sizeof_int = 4;
sizeof_long = 8;
sizeof_long_long = 8;
sizeof_float = 4;
sizeof_double = 8;
sizeof_long_double = 16;
sizeof_wchar_t = 4;
sizeof_size_t = 8;
sizeof_pointer = 8;
defaultSign = '\0';
char_bit = 8;
short_bit = char_bit * sizeof_short;
int_bit = char_bit * sizeof_int;
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;
// read from platform file
return true;
case Type::File:
type = t;
// sizes are not set.
return false;
}
Expand All @@ -152,40 +76,90 @@ bool Platform::set(Type t)

bool Platform::set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool debug)
{
if (platformstr == "win32A")
set(Type::Win32A);
else if (platformstr == "win32W")
set(Type::Win32W);
else if (platformstr == "win64")
set(Type::Win64);
else if (platformstr == "unix32")
set(Type::Unix32);
else if (platformstr == "unix64")
set(Type::Unix64);
else if (platformstr == "native")
set(Type::Native);
else if (platformstr == "unspecified")
set(Type::Unspecified);
Type t;
std::string platformFile;

if (platformstr == "win32A") {
// TODO: deprecate
//std::cout << "Platform 'win32A' is deprecated and will be removed in a future version. Please use 'win32a' instead." << std::endl;
t = Type::Win32A;
platformFile = "win32";
}
else if (platformstr == "win32a") {
// TODO: deprecate if we have proper UNICODE support in win32.cfg
t = Type::Win32A;
platformFile = "win32";
}
else if (platformstr == "win32W") {
// TODO: deprecate
//std::cout << "Platform 'win32W' is deprecated and will be removed in a future version. Please use 'win32w' instead." << std::endl;
t = Type::Win32W;
platformFile = "win32";
}
else if (platformstr == "win32w") {
// TODO: deprecate if we have proper UNICODE support in win32.cfg
t = Type::Win32W;
platformFile = "win32";
}
else if (platformstr == "win32") {
t = Type::Win32A;
platformFile = platformstr;
}
else if (platformstr == "win64") {
t = Type::Win64;
platformFile = platformstr;
}
else if (platformstr == "unix32") {
t = Type::Unix32;
platformFile = platformstr;
}
else if (platformstr == "unix32-unsigned") {
std::cout << "Platform 'unix32-unsigned' is deprecated and will be removed in Cppcheck 2.18. Please use '--platform=unix32 --funsigned-char' instead." << std::endl;
t = Type::Unix32;
platformFile = platformstr;
}
else if (platformstr == "unix64") {
t = Type::Unix64;
platformFile = platformstr;
}
else if (platformstr == "unix64-unsigned") {
std::cout << "Platform 'unix64-unsigned' is deprecated and will be removed in Cppcheck 2.18. Please use '--platform=unix64 --funsigned-char' instead." << std::endl;
t = Type::Unix64;
platformFile = platformstr;
}
else if (platformstr == "native") {
t = Type::Native;
}
else if (platformstr == "unspecified") {
std::cout << "Platform 'unspecified' is deprecated and will be removed in a future version. It is also now identical to 'native' (i.e. char type signedness based on compiler instead of unknown)." << std::endl;
t = Type::Unspecified;
}
else if (paths.empty()) {
errstr = "unrecognized platform: '" + platformstr + "' (no lookup).";
return false;
}
else {
t = Type::File;
platformFile = platformstr;
}

if (!platformFile.empty()) {
bool found = false;
for (const std::string& path : paths) {
if (debug)
std::cout << "looking for platform '" + platformstr + "' in '" + path + "'" << std::endl;
if (loadFromFile(path.c_str(), platformstr, debug)) {
std::cout << "looking for platform '" + platformFile + "' in '" + path + "'" << std::endl;
if (loadFromFile(path.c_str(), platformFile, debug)) {
found = true;
break;
}
}
if (!found) {
errstr = "unrecognized platform: '" + platformstr + "'.";
errstr = "unrecognized platform: '" + platformFile + "'.";
return false;
}
}

set(t);
return true;
}

Expand Down Expand Up @@ -248,13 +222,14 @@ bool Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc)
if (!rootnode || std::strcmp(rootnode->Name(), "platform") != 0)
return false;

// TODO: warn about missing fields
bool error = false;
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
const char* name = node->Name();
if (std::strcmp(name, "default-sign") == 0) {
const char* str = node->GetText();
if (str)
defaultSign = *str;
defaultSign = *str; // TODO: warn if neither 'u' nor 's'
else
error = true;
} else if (std::strcmp(name, "char_bit") == 0)
Expand Down Expand Up @@ -293,7 +268,6 @@ bool Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc)
long_bit = char_bit * sizeof_long;
long_long_bit = char_bit * sizeof_long_long;

type = Type::File;
return !error;
}

Expand Down
6 changes: 2 additions & 4 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, E
if (!mTokenizer.tokens())
return;

if (mSettings.platform.defaultSign == 's' || mSettings.platform.defaultSign == 'S')
mDefaultSignedness = ValueType::SIGNED;
else if (mSettings.platform.defaultSign == 'u' || mSettings.platform.defaultSign == 'U')
if (mSettings.platform.defaultSign == 'u')
mDefaultSignedness = ValueType::UNSIGNED;
else
mDefaultSignedness = ValueType::UNKNOWN_SIGN;
mDefaultSignedness = ValueType::SIGNED;

createSymbolDatabaseFindAllScopes();
createSymbolDatabaseClassInfo();
Expand Down
18 changes: 18 additions & 0 deletions platforms/unix32.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<platform>
<char_bit>8</char_bit>
<default-sign>signed</default-sign>
<sizeof>
<bool>1</bool>
<short>2</short>
<int>4</int>
<long>4</long>
<long-long>8</long-long>
<float>4</float>
<double>8</double>
<long-double>12</long-double>
<pointer>4</pointer>
<size_t>4</size_t>
<wchar_t>4</wchar_t>
</sizeof>
</platform>
18 changes: 18 additions & 0 deletions platforms/unix64.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<platform>
<char_bit>8</char_bit>
<default-sign>signed</default-sign>
<sizeof>
<bool>1</bool>
<short>2</short>
<int>4</int>
<long>8</long>
<long-long>8</long-long>
<float>4</float>
<double>8</double>
<long-double>16</long-double>
<pointer>8</pointer>
<size_t>8</size_t>
<wchar_t>4</wchar_t>
</sizeof>
</platform>
18 changes: 18 additions & 0 deletions platforms/win32.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<platform>
<char_bit>8</char_bit>
<default-sign>signed</default-sign>
<sizeof>
<bool>1</bool><!--4 in Visual C++ 4.2-->
<short>2</short>
<int>4</int>
<long>4</long>
<long-long>8</long-long>
<float>4</float>
<double>8</double>
<long-double>8</long-double>
<pointer>4</pointer>
<size_t>4</size_t>
<wchar_t>2</wchar_t>
</sizeof>
</platform>
18 changes: 18 additions & 0 deletions platforms/win64.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<platform>
<char_bit>8</char_bit>
<default-sign>signed</default-sign>
<sizeof>
<bool>1</bool>
<short>2</short>
<int>4</int>
<long>4</long>
<long-long>8</long-long>
<float>4</float>
<double>8</double>
<long-double>8</long-double>
<pointer>8</pointer>
<size_t>8</size_t>
<wchar_t>2</wchar_t>
</sizeof>
</platform>
7 changes: 6 additions & 1 deletion releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ Changed interface:
-

Deprecations:
- The "unix32-unsigned" and "unix64-unsigned" platforms have been deprecated and will be removed in Cppcheck 2.18. Please use "--platform=unix32 --funsigned-char" and "--platform=unix64 --funsigned-char" respectively instead.
- The "unspecified" platform has been deprecated and will be removed in a future version. It is also now identical to 'native' (i.e. char type signedness based on compiler instead of unknown).
-

Other:
- Removed deperecated support for builds via qmake.
- Removed deprecated support for builds via qmake.
- The `win32a` and `win32w` aliases have been added for the platforms `win32A` and `win32W` respectively.
- The possibility of an unknown signedness of the char type in a platform definition has been removed.
- The built-in "win*" and "unix*" platforms will now default to signed char type instead of unknown signedness. If you require unsigned chars please specify "--funsigned-char"
-
40 changes: 40 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2276,3 +2276,43 @@ def test_dumpfile_platform(tmpdir):
break
assert ' wchar_t_bit="' in platform
assert ' size_t_bit="' in platform


def test_custom_platform(tmpdir):
test_cfg = os.path.join(tmpdir, 'test.cfg')
with open(test_cfg, 'wt') as f:
f.write("""
<?xml version="1.0"?>
<platform>
<char_bit>8</char_bit>
<default-sign>unsigned</default-sign>
<sizeof>
<bool>1</bool>
<short>2</short>
<int>2</int>
<long>4</long>
<long-long>8</long-long>
<float>4</float>
<double>4</double>
<long-double>4</long-double>
<pointer>2</pointer>
<size_t>2</size_t>
<wchar_t>2</wchar_t>
</sizeof>
</platform>
""")

# TODO: use a sample to make sure the file is actually used
test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
f.write("""
""")
args = ['--platform={}'.format(test_cfg), test_file]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0, stdout
lines = stdout.splitlines()
assert lines == [
'Checking {} ...'.format(test_file)
]
assert stderr == ''
Empty file added test/cli/test-other.py
Empty file.
Loading