|
Packit |
2035a7 |
/*
|
|
Packit |
2035a7 |
* Cppcheck - A tool for static C/C++ code analysis
|
|
Packit |
2035a7 |
* Copyright (C) 2007-2018 Cppcheck team.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* This program is free software: you can redistribute it and/or modify
|
|
Packit |
2035a7 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
2035a7 |
* the Free Software Foundation, either version 3 of the License, or
|
|
Packit |
2035a7 |
* (at your option) any later version.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
2035a7 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
2035a7 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
2035a7 |
* GNU General Public License for more details.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
2035a7 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
2035a7 |
*/
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
//---------------------------------------------------------------------------
|
|
Packit |
2035a7 |
#ifndef platformH
|
|
Packit |
2035a7 |
#define platformH
|
|
Packit |
2035a7 |
//---------------------------------------------------------------------------
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
#include "config.h"
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
#include <string>
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/// @addtogroup Core
|
|
Packit |
2035a7 |
/// @{
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
namespace tinyxml2 {
|
|
Packit |
2035a7 |
class XMLDocument;
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
namespace cppcheck {
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/**
|
|
Packit |
2035a7 |
* @brief Platform settings
|
|
Packit |
2035a7 |
*/
|
|
Packit |
2035a7 |
class CPPCHECKLIB Platform {
|
|
Packit |
2035a7 |
private:
|
|
Packit |
2035a7 |
static long long min_value(int bit) {
|
|
Packit |
2035a7 |
if (bit >= 64)
|
|
Packit |
2035a7 |
return 1LL << 63;
|
|
Packit |
2035a7 |
return -(1LL << (bit-1));
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
static long long max_value(int bit) {
|
|
Packit |
2035a7 |
if (bit >= 64)
|
|
Packit |
2035a7 |
return (~0ULL) >> 1;
|
|
Packit |
2035a7 |
return (1LL << (bit-1)) - 1LL;
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
public:
|
|
Packit |
2035a7 |
Platform();
|
|
Packit |
2035a7 |
virtual ~Platform() {}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
bool isIntValue(long long value) const {
|
|
Packit |
2035a7 |
return value >= min_value(int_bit) && value <= max_value(int_bit);
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
bool isLongValue(long long value) const {
|
|
Packit |
2035a7 |
return value >= min_value(long_bit) && value <= max_value(long_bit);
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
unsigned int char_bit; /// bits in char
|
|
Packit |
2035a7 |
unsigned int short_bit; /// bits in short
|
|
Packit |
2035a7 |
unsigned int int_bit; /// bits in int
|
|
Packit |
2035a7 |
unsigned int long_bit; /// bits in long
|
|
Packit |
2035a7 |
unsigned int long_long_bit; /// bits in long long
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/** size of standard types */
|
|
Packit |
2035a7 |
unsigned int sizeof_bool;
|
|
Packit |
2035a7 |
unsigned int sizeof_short;
|
|
Packit |
2035a7 |
unsigned int sizeof_int;
|
|
Packit |
2035a7 |
unsigned int sizeof_long;
|
|
Packit |
2035a7 |
unsigned int sizeof_long_long;
|
|
Packit |
2035a7 |
unsigned int sizeof_float;
|
|
Packit |
2035a7 |
unsigned int sizeof_double;
|
|
Packit |
2035a7 |
unsigned int sizeof_long_double;
|
|
Packit |
2035a7 |
unsigned int sizeof_wchar_t;
|
|
Packit |
2035a7 |
unsigned int sizeof_size_t;
|
|
Packit |
2035a7 |
unsigned int sizeof_pointer;
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
char defaultSign; // unsigned:'u', signed:'s', unknown:'\0'
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
enum PlatformType {
|
|
Packit |
2035a7 |
Unspecified, // No platform specified
|
|
Packit |
2035a7 |
Native, // whatever system this code was compiled on
|
|
Packit |
2035a7 |
Win32A,
|
|
Packit |
2035a7 |
Win32W,
|
|
Packit |
2035a7 |
Win64,
|
|
Packit |
2035a7 |
Unix32,
|
|
Packit |
2035a7 |
Unix64,
|
|
Packit |
2035a7 |
PlatformFile
|
|
Packit |
2035a7 |
};
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/** platform type */
|
|
Packit |
2035a7 |
PlatformType platformType;
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/** set the platform type for predefined platforms */
|
|
Packit |
2035a7 |
bool platform(PlatformType type);
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/**
|
|
Packit |
2035a7 |
* load platform file
|
|
Packit |
2035a7 |
* @param exename application path
|
|
Packit |
2035a7 |
* @param filename platform filename
|
|
Packit |
2035a7 |
* @return returns true if file was loaded successfully
|
|
Packit |
2035a7 |
*/
|
|
Packit |
2035a7 |
bool loadPlatformFile(const char exename[], const std::string &filename);
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/** load platform from xml document, primarily for testing */
|
|
Packit |
2035a7 |
bool loadFromXmlDocument(const tinyxml2::XMLDocument *doc);
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/**
|
|
Packit |
2035a7 |
* @brief Returns true if platform type is Windows
|
|
Packit |
2035a7 |
* @return true if Windows platform type.
|
|
Packit |
2035a7 |
*/
|
|
Packit |
2035a7 |
bool isWindowsPlatform() const {
|
|
Packit |
2035a7 |
return platformType == Win32A ||
|
|
Packit |
2035a7 |
platformType == Win32W ||
|
|
Packit |
2035a7 |
platformType == Win64;
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
const char *platformString() const {
|
|
Packit |
2035a7 |
return platformString(platformType);
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
static const char *platformString(PlatformType pt) {
|
|
Packit |
2035a7 |
switch (pt) {
|
|
Packit |
2035a7 |
case Unspecified:
|
|
Packit |
2035a7 |
return "Unspecified";
|
|
Packit |
2035a7 |
case Native:
|
|
Packit |
2035a7 |
return "Native";
|
|
Packit |
2035a7 |
case Win32A:
|
|
Packit |
2035a7 |
return "win32A";
|
|
Packit |
2035a7 |
case Win32W:
|
|
Packit |
2035a7 |
return "win32W";
|
|
Packit |
2035a7 |
case Win64:
|
|
Packit |
2035a7 |
return "win64";
|
|
Packit |
2035a7 |
case Unix32:
|
|
Packit |
2035a7 |
return "unix32";
|
|
Packit |
2035a7 |
case Unix64:
|
|
Packit |
2035a7 |
return "unix64";
|
|
Packit |
2035a7 |
case PlatformFile:
|
|
Packit |
2035a7 |
return "platformFile";
|
|
Packit |
2035a7 |
default:
|
|
Packit |
2035a7 |
return "unknown";
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
long long unsignedCharMax() const {
|
|
Packit |
2035a7 |
return max_value(char_bit + 1);
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
long long signedCharMax() const {
|
|
Packit |
2035a7 |
return max_value(char_bit);
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
long long signedCharMin() const {
|
|
Packit |
2035a7 |
return min_value(char_bit);
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
};
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
/// @}
|
|
Packit |
2035a7 |
//---------------------------------------------------------------------------
|
|
Packit |
2035a7 |
#endif // platformH
|