2016-08-13 10:50:03 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2018-01-14 15:37:52 +01:00
|
|
|
* Copyright (C) 2007-2017 Cppcheck team.
|
2016-08-13 10:50:03 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#ifndef platformH
|
|
|
|
#define platformH
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "config.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
|
2016-08-13 10:50:03 +02:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
/// @addtogroup Core
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
namespace cppcheck {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Platform settings
|
|
|
|
*/
|
|
|
|
class CPPCHECKLIB Platform {
|
2016-10-16 11:36:22 +02:00
|
|
|
private:
|
2017-02-27 13:22:10 +01:00
|
|
|
static long long min_value(int bit) {
|
2016-10-16 12:00:33 +02:00
|
|
|
if (bit >= 64)
|
2016-10-16 11:36:22 +02:00
|
|
|
return 1LL << 63;
|
2016-10-16 12:00:33 +02:00
|
|
|
return -(1LL << (bit-1));
|
2016-10-16 11:36:22 +02:00
|
|
|
}
|
|
|
|
|
2017-02-27 13:22:10 +01:00
|
|
|
static long long max_value(int bit) {
|
2016-10-16 12:00:33 +02:00
|
|
|
if (bit >= 64)
|
2016-10-16 11:36:22 +02:00
|
|
|
return (~0ULL) >> 1;
|
2016-10-16 12:00:33 +02:00
|
|
|
return (1LL << (bit-1)) - 1LL;
|
2016-10-16 11:36:22 +02:00
|
|
|
}
|
2016-08-13 10:50:03 +02:00
|
|
|
public:
|
|
|
|
Platform();
|
|
|
|
virtual ~Platform() {}
|
|
|
|
|
2016-10-16 11:36:22 +02:00
|
|
|
bool isIntValue(long long value) const {
|
2016-10-16 12:00:33 +02:00
|
|
|
return value >= min_value(int_bit) && value <= max_value(int_bit);
|
2016-10-16 11:36:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isLongValue(long long value) const {
|
2016-10-16 12:00:33 +02:00
|
|
|
return value >= min_value(long_bit) && value <= max_value(long_bit);
|
2016-10-16 11:36:22 +02:00
|
|
|
}
|
|
|
|
|
2016-08-13 10:50:03 +02:00
|
|
|
unsigned int char_bit; /// bits in char
|
|
|
|
unsigned int short_bit; /// bits in short
|
|
|
|
unsigned int int_bit; /// bits in int
|
|
|
|
unsigned int long_bit; /// bits in long
|
|
|
|
unsigned int long_long_bit; /// bits in long long
|
|
|
|
|
|
|
|
/** size of standard types */
|
|
|
|
unsigned int sizeof_bool;
|
|
|
|
unsigned int sizeof_short;
|
|
|
|
unsigned int sizeof_int;
|
|
|
|
unsigned int sizeof_long;
|
|
|
|
unsigned int sizeof_long_long;
|
|
|
|
unsigned int sizeof_float;
|
|
|
|
unsigned int sizeof_double;
|
|
|
|
unsigned int sizeof_long_double;
|
|
|
|
unsigned int sizeof_wchar_t;
|
|
|
|
unsigned int sizeof_size_t;
|
|
|
|
unsigned int sizeof_pointer;
|
|
|
|
|
|
|
|
char defaultSign; // unsigned:'u', signed:'s', unknown:'\0'
|
|
|
|
|
|
|
|
enum PlatformType {
|
|
|
|
Unspecified, // No platform specified
|
|
|
|
Native, // whatever system this code was compiled on
|
|
|
|
Win32A,
|
|
|
|
Win32W,
|
|
|
|
Win64,
|
|
|
|
Unix32,
|
2017-05-22 14:46:19 +02:00
|
|
|
Unix64,
|
2017-08-09 11:06:31 +02:00
|
|
|
PlatformFile
|
2016-08-13 10:50:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/** platform type */
|
|
|
|
PlatformType platformType;
|
|
|
|
|
|
|
|
/** set the platform type for predefined platforms */
|
|
|
|
bool platform(PlatformType type);
|
|
|
|
|
|
|
|
/** set the platform type for user specified platforms */
|
2018-02-09 16:22:22 +01:00
|
|
|
bool platformFile(const char exename[], const std::string &filename);
|
2016-08-13 10:50:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns true if platform type is Windows
|
|
|
|
* @return true if Windows platform type.
|
|
|
|
*/
|
|
|
|
bool isWindowsPlatform() const {
|
|
|
|
return platformType == Win32A ||
|
|
|
|
platformType == Win32W ||
|
|
|
|
platformType == Win64;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *platformString() const {
|
|
|
|
switch (platformType) {
|
2017-06-06 22:15:11 +02:00
|
|
|
case Unspecified:
|
|
|
|
return "Unspecified";
|
|
|
|
case Native:
|
|
|
|
return "Native";
|
2016-08-13 10:50:03 +02:00
|
|
|
case Win32A:
|
|
|
|
return "win32A";
|
|
|
|
case Win32W:
|
|
|
|
return "win32W";
|
|
|
|
case Win64:
|
|
|
|
return "win64";
|
2017-06-06 22:15:11 +02:00
|
|
|
case Unix32:
|
|
|
|
return "unix32";
|
|
|
|
case Unix64:
|
|
|
|
return "unix64";
|
2017-08-09 11:06:31 +02:00
|
|
|
case PlatformFile:
|
|
|
|
return "platformFile";
|
2016-08-13 10:50:03 +02:00
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
2017-10-18 17:30:47 +02:00
|
|
|
|
|
|
|
long long unsignedCharMax() const {
|
2017-10-20 01:53:20 +02:00
|
|
|
return max_value(char_bit + 1);
|
2017-10-18 17:30:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
long long signedCharMax() const {
|
|
|
|
return max_value(char_bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
long long signedCharMin() const {
|
|
|
|
return min_value(char_bit);
|
|
|
|
}
|
2016-08-13 10:50:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif // platformH
|