-
Notifications
You must be signed in to change notification settings - Fork 1.6k
added clean C/C++ keyword lists and use them in TokenList
#3774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| /* | ||
| * Cppcheck - A tool for static C/C++ code analysis | ||
| * Copyright (C) 2007-2023 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" | ||
|
|
||
| // 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" | ||
|
|
||
| #ifdef __clang__ | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wunused-macros" | ||
| #endif | ||
|
|
||
| #define C23_KEYWORDS \ | ||
| "alignas", "alignof", "bool", "false", "nullptr", "static_assert", "thread_local", "true", "typeof", "typeof_unqual", \ | ||
| "_BitInt", "_Decimal128", "_Decimal32", "_Decimal64" | ||
|
|
||
| #ifdef __clang__ | ||
| #pragma clang diagnostic pop | ||
| #endif | ||
|
|
||
| static const std::unordered_set<std::string> c89_keywords_all = { | ||
| C90_KEYWORDS | ||
| }; | ||
|
|
||
| static const std::unordered_set<std::string> c89_keywords = c89_keywords_all; | ||
|
|
||
| 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> 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", \ | ||
| "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 \ | ||
| "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_all; | ||
|
|
||
| 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 = cpp11_keywords_all; | ||
|
|
||
| static const std::unordered_set<std::string> cpp14_keywords; | ||
|
|
||
| static const std::unordered_set<std::string> cpp17_keywords_all = cpp11_keywords_all; | ||
|
|
||
| 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 = cpp20_keywords_all; | ||
|
|
||
| // 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::C23: | ||
| return c23_keywords_all;*/ | ||
| } | ||
| } | ||
|
|
||
| // 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; | ||
| } | ||
| } | ||
|
|
||
| // 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::C23: | ||
| return c23_keywords_all;*/ | ||
| } | ||
| } | ||
|
|
||
| // 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; | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Cppcheck - A tool for static C/C++ code analysis | ||
| * Copyright (C) 2007-2023 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/>. | ||
| */ | ||
|
|
||
| #ifndef keywordsH | ||
| #define keywordsH | ||
|
|
||
| #include "standards.h" | ||
|
|
||
| #include <string> | ||
| #include <unordered_set> | ||
|
|
||
| class Keywords | ||
| { | ||
| public: | ||
| static const std::unordered_set<std::string>& getAll(Standards::cstd_t cStd); | ||
| static const std::unordered_set<std::string>& getAll(Standards::cppstd_t cppStd); | ||
|
|
||
| static const std::unordered_set<std::string>& getOnly(Standards::cstd_t cStd); | ||
| static const std::unordered_set<std::string>& getOnly(Standards::cppstd_t cppStd); | ||
| }; | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.