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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
/*
* 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 "keywords.h"
#include "utils.h"
// see https://en.cppreference.com/w/c/keyword
#define C90_KEYWORDS \
"auto", "break", "case", "char", "const", "continue", "default", \
"do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", "long", \
"register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", \
"union", "unsigned", "void", "volatile", "while"
#define C99_KEYWORDS \
"inline", "restrict", "_Bool", "_Complex", "_Imaginary"
#define C11_KEYWORDS \
"_Alignas", "_Alignof", "_Atomic", "_Generic", "_Noreturn", "_Static_assert", "_Thread_local"
#define C23_KEYWORDS \
"alignas", "alignof", "bool", "constexpr", "false", "nullptr", "static_assert", "thread_local", "true", "typeof", "typeof_unqual", \
"_BitInt", "_Decimal128", "_Decimal32", "_Decimal64"
static const std::unordered_set<std::string> c89_keywords_all = {
C90_KEYWORDS
};
static const std::unordered_set<std::string> c89_keywords = {
C90_KEYWORDS
};
static const std::unordered_set<std::string> c99_keywords_all = {
C90_KEYWORDS, C99_KEYWORDS
};
static const std::unordered_set<std::string> c99_keywords = {
C99_KEYWORDS
};
static const std::unordered_set<std::string> c11_keywords_all = {
C90_KEYWORDS, C99_KEYWORDS, C11_KEYWORDS
};
static const std::unordered_set<std::string> c11_keywords = {
C11_KEYWORDS
};
static const std::unordered_set<std::string> c17_keywords_all = {
C90_KEYWORDS, C99_KEYWORDS, C11_KEYWORDS
};
static const std::unordered_set<std::string> c17_keywords = {
};
static const std::unordered_set<std::string> c23_keywords_all = {
C90_KEYWORDS, C99_KEYWORDS, C11_KEYWORDS, C23_KEYWORDS
};
static const std::unordered_set<std::string> c23_keywords = {
C23_KEYWORDS
};
// see https://en.cppreference.com/w/cpp/keyword
#define CPP03_KEYWORDS \
"and", "and_eq", "asm", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", \
"class", "compl", "const", "const_cast", "continue", "default", \
"delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", \
"float", "for", "friend", "goto", "if", "inline", "int", "long", \
"mutable", "namespace", "new", "not", "not_eq", "operator", \
"or", "or_eq", "private", "protected", "public", "register", "reinterpret_cast", \
"return", "short", "signed", "sizeof", "static", \
"static_cast", "struct", "switch", "template", "this", "throw", \
"true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", \
"virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq"
#define CPP11_KEYWORDS \
"alignas", "alignof", "char16_t", "char32_t", "constexpr", "decltype", \
"noexcept", "nullptr", "static_assert", "thread_local"
#define CPP20_KEYWORDS \
"char8_t", "concept", "consteval", "constinit", "co_await", \
"co_return", "co_yield", "requires"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
#endif
#define CPP_TMTS_KEYWORDS \
"atomic_cancel", "atomic_commit", "atomic_noexcept", "synchronized"
#define CPP_REFL_TS_KEYWORDS \
"reflexpr"
#ifdef __clang__
#pragma clang diagnostic pop
#endif
static const std::unordered_set<std::string> cpp03_keywords_all = {
CPP03_KEYWORDS
};
static const std::unordered_set<std::string> cpp03_keywords = {
CPP03_KEYWORDS
};
static const std::unordered_set<std::string> cpp11_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS
};
static const std::unordered_set<std::string> cpp11_keywords = {
CPP11_KEYWORDS
};
static const std::unordered_set<std::string> cpp14_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS
};
static const std::unordered_set<std::string> cpp14_keywords = {
};
static const std::unordered_set<std::string> cpp17_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS
};
static const std::unordered_set<std::string> cpp17_keywords = {
};
static const std::unordered_set<std::string> cpp20_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
};
static const std::unordered_set<std::string> cpp20_keywords = {
CPP20_KEYWORDS
};
static const std::unordered_set<std::string> cpp23_keywords = {
};
static const std::unordered_set<std::string> cpp23_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
};
static const std::unordered_set<std::string> cpp26_keywords = {
};
static const std::unordered_set<std::string> cpp26_keywords_all = {
CPP03_KEYWORDS, CPP11_KEYWORDS, CPP20_KEYWORDS
};
// cppcheck-suppress unusedFunction
const std::unordered_set<std::string>& Keywords::getAll(Standards::cstd_t cStd)
{
// cppcheck-suppress missingReturn
switch (cStd) {
case Standards::cstd_t::C89:
return c89_keywords_all;
case Standards::cstd_t::C99:
return c99_keywords_all;
case Standards::cstd_t::C11:
return c11_keywords_all;
case Standards::cstd_t::C17:
return c17_keywords_all;
case Standards::cstd_t::C23:
return c23_keywords_all;
}
cppcheck::unreachable();
}
// cppcheck-suppress unusedFunction
const std::unordered_set<std::string>& Keywords::getAll(Standards::cppstd_t cppStd) {
// cppcheck-suppress missingReturn
switch (cppStd) {
case Standards::cppstd_t::CPP03:
return cpp03_keywords_all;
case Standards::cppstd_t::CPP11:
return cpp11_keywords_all;
case Standards::cppstd_t::CPP14:
return cpp14_keywords_all;
case Standards::cppstd_t::CPP17:
return cpp17_keywords_all;
case Standards::cppstd_t::CPP20:
return cpp20_keywords_all;
case Standards::cppstd_t::CPP23:
return cpp23_keywords_all;
case Standards::cppstd_t::CPP26:
return cpp26_keywords_all;
}
cppcheck::unreachable();
}
// cppcheck-suppress unusedFunction
const std::unordered_set<std::string>& Keywords::getOnly(Standards::cstd_t cStd)
{
// cppcheck-suppress missingReturn
switch (cStd) {
case Standards::cstd_t::C89:
return c89_keywords;
case Standards::cstd_t::C99:
return c99_keywords;
case Standards::cstd_t::C11:
return c11_keywords;
case Standards::cstd_t::C17:
return c17_keywords;
case Standards::cstd_t::C23:
return c23_keywords;
}
cppcheck::unreachable();
}
// cppcheck-suppress unusedFunction
const std::unordered_set<std::string>& Keywords::getOnly(Standards::cppstd_t cppStd)
{
// cppcheck-suppress missingReturn
switch (cppStd) {
case Standards::cppstd_t::CPP03:
return cpp03_keywords;
case Standards::cppstd_t::CPP11:
return cpp11_keywords;
case Standards::cppstd_t::CPP14:
return cpp14_keywords;
case Standards::cppstd_t::CPP17:
return cpp17_keywords;
case Standards::cppstd_t::CPP20:
return cpp20_keywords;
case Standards::cppstd_t::CPP23:
return cpp23_keywords;
case Standards::cppstd_t::CPP26:
return cpp26_keywords;
}
cppcheck::unreachable();
}
|