1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2024 Cppcheck team.
*
* 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/>.
*/
#include "standards.h"
#include "utils.h"
#include <utility>
#include <simplecpp.h>
static Standards::cstd_t mapC(simplecpp::cstd_t cstd) {
switch (cstd)
{
case simplecpp::C89:
return Standards::C89;
case simplecpp::C99:
return Standards::C99;
case simplecpp::C11:
return Standards::C11;
case simplecpp::C17:
return Standards::C17;
case simplecpp::C23:
return Standards::C23;
case simplecpp::CUnknown:
return Standards::CLatest;
}
cppcheck::unreachable();
}
bool Standards::setC(std::string str)
{
if (str.empty())
return false;
const simplecpp::cstd_t c_new = simplecpp::getCStd(str);
const bool b = (c_new != simplecpp::CUnknown);
if (b) {
c = mapC(c_new);
stdValueC = std::move(str);
}
return b;
}
std::string Standards::getC() const
{
return getC(c);
}
std::string Standards::getC(cstd_t c_std)
{
switch (c_std) {
case C89:
return "c89";
case C99:
return "c99";
case C11:
return "c11";
case C17:
return "c17";
case C23:
return "c23";
}
return "";
}
Standards::cstd_t Standards::getC(const std::string &std)
{
return mapC(simplecpp::getCStd(std));
}
static Standards::cppstd_t mapCPP(simplecpp::cppstd_t cppstd) {
switch (cppstd)
{
case simplecpp::CPP03:
return Standards::CPP03;
case simplecpp::CPP11:
return Standards::CPP11;
case simplecpp::CPP14:
return Standards::CPP14;
case simplecpp::CPP17:
return Standards::CPP17;
case simplecpp::CPP20:
return Standards::CPP20;
case simplecpp::CPP23:
return Standards::CPP23;
case simplecpp::CPP26:
return Standards::CPP26;
case simplecpp::CPPUnknown:
return Standards::CPPLatest;
}
cppcheck::unreachable();
}
bool Standards::setCPP(std::string str)
{
if (str.empty())
return false;
const simplecpp::cppstd_t cpp_new = simplecpp::getCppStd(str);
const bool b = (cpp_new != simplecpp::CPPUnknown);
if (b) {
cpp = mapCPP(cpp_new);
stdValueCPP = std::move(str);
}
return b;
}
std::string Standards::getCPP() const
{
return getCPP(cpp);
}
std::string Standards::getCPP(cppstd_t std)
{
switch (std) {
case CPP03:
return "c++03";
case CPP11:
return "c++11";
case CPP14:
return "c++14";
case CPP17:
return "c++17";
case CPP20:
return "c++20";
case CPP23:
return "c++23";
case CPP26:
return "c++26";
}
return "";
}
Standards::cppstd_t Standards::getCPP(const std::string &std)
{
return mapCPP(simplecpp::getCppStd(std));
}
bool Standards::setStd(const std::string& str)
{
return setC(str) || setCPP(str);
}
|