/src/cppcheck/lib/standards.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Cppcheck - A tool for static C/C++ code analysis |
3 | | * Copyright (C) 2007-2023 Cppcheck team. |
4 | | * |
5 | | * This program is free software: you can redistribute it and/or modify |
6 | | * it under the terms of the GNU General Public License as published by |
7 | | * the Free Software Foundation, either version 3 of the License, or |
8 | | * (at your option) any later version. |
9 | | * |
10 | | * This program is distributed in the hope that it will be useful, |
11 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | * GNU General Public License for more details. |
14 | | * |
15 | | * You should have received a copy of the GNU General Public License |
16 | | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | | */ |
18 | | |
19 | | //--------------------------------------------------------------------------- |
20 | | #ifndef standardsH |
21 | | #define standardsH |
22 | | //--------------------------------------------------------------------------- |
23 | | |
24 | | #include "utils.h" |
25 | | |
26 | | #include <string> |
27 | | |
28 | | /// @addtogroup Core |
29 | | /// @{ |
30 | | |
31 | | |
32 | | /** |
33 | | * @brief This is just a container for standards settings. |
34 | | * This struct contains all possible standards that cppcheck recognize. |
35 | | */ |
36 | | struct Standards { |
37 | | /** C code standard */ |
38 | | enum cstd_t { C89, C99, C11, CLatest = C11 } c = CLatest; |
39 | | |
40 | | /** C++ code standard */ |
41 | | enum cppstd_t { CPP03, CPP11, CPP14, CPP17, CPP20, CPP23, CPPLatest = CPP23 } cpp = CPPLatest; |
42 | | |
43 | | /** --std value given on command line */ |
44 | | std::string stdValue; |
45 | | |
46 | 0 | bool setC(const std::string& str) { |
47 | 0 | stdValue = str; |
48 | 0 | if (str == "c89" || str == "C89") { |
49 | 0 | c = C89; |
50 | 0 | return true; |
51 | 0 | } |
52 | 0 | if (str == "c99" || str == "C99") { |
53 | 0 | c = C99; |
54 | 0 | return true; |
55 | 0 | } |
56 | 0 | if (str == "c11" || str == "C11") { |
57 | 0 | c = C11; |
58 | 0 | return true; |
59 | 0 | } |
60 | 0 | return false; |
61 | 0 | } |
62 | 0 | const std::string getC() const { |
63 | 0 | switch (c) { |
64 | 0 | case C89: |
65 | 0 | return "c89"; |
66 | 0 | case C99: |
67 | 0 | return "c99"; |
68 | 0 | case C11: |
69 | 0 | return "c11"; |
70 | 0 | } |
71 | 0 | return ""; |
72 | 0 | } |
73 | 0 | static cstd_t getC(const std::string &std) { |
74 | 0 | if (std == "c89") { |
75 | 0 | return Standards::C89; |
76 | 0 | } |
77 | 0 | if (std == "c99") { |
78 | 0 | return Standards::C99; |
79 | 0 | } |
80 | 0 | if (std == "c11") { |
81 | 0 | return Standards::C11; |
82 | 0 | } |
83 | 0 | return Standards::CLatest; |
84 | 0 | } |
85 | 0 | bool setCPP(std::string str) { |
86 | 0 | stdValue = str; |
87 | 0 | strTolower(str); |
88 | 0 | cpp = getCPP(str); |
89 | 0 | return !stdValue.empty() && str == getCPP(); |
90 | 0 | } |
91 | 2.72k | std::string getCPP() const { |
92 | 2.72k | return getCPP(cpp); |
93 | 2.72k | } |
94 | 2.72k | static std::string getCPP(cppstd_t std) { |
95 | 2.72k | switch (std) { |
96 | 0 | case CPP03: |
97 | 0 | return "c++03"; |
98 | 0 | case CPP11: |
99 | 0 | return "c++11"; |
100 | 0 | case CPP14: |
101 | 0 | return "c++14"; |
102 | 0 | case CPP17: |
103 | 0 | return "c++17"; |
104 | 0 | case CPP20: |
105 | 0 | return "c++20"; |
106 | 2.72k | case CPP23: |
107 | 2.72k | return "c++23"; |
108 | 2.72k | } |
109 | 0 | return ""; |
110 | 2.72k | } |
111 | 0 | static cppstd_t getCPP(const std::string &std) { |
112 | 0 | if (std == "c++03") { |
113 | 0 | return Standards::CPP03; |
114 | 0 | } |
115 | 0 | if (std == "c++11") { |
116 | 0 | return Standards::CPP11; |
117 | 0 | } |
118 | 0 | if (std == "c++14") { |
119 | 0 | return Standards::CPP14; |
120 | 0 | } |
121 | 0 | if (std == "c++17") { |
122 | 0 | return Standards::CPP17; |
123 | 0 | } |
124 | 0 | if (std == "c++20") { |
125 | 0 | return Standards::CPP20; |
126 | 0 | } |
127 | 0 | if (std == "c++23") { |
128 | 0 | return Standards::CPP23; |
129 | 0 | } |
130 | 0 | return Standards::CPPLatest; |
131 | 0 | } |
132 | | }; |
133 | | |
134 | | /// @} |
135 | | //--------------------------------------------------------------------------- |
136 | | #endif // standardsH |