symboldatabase.cpp: use `Keywords` / added TODOs (#4828)

This commit is contained in:
Oliver Stöneberg 2023-03-02 21:20:56 +01:00 committed by GitHub
parent 51c5a79150
commit 75619db1d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 28 deletions

View File

@ -604,7 +604,7 @@ $(libcppdir)/summaries.o: lib/summaries.cpp lib/analyzerinfo.h lib/config.h lib/
$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/mathlib.h lib/path.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/suppressions.cpp
$(libcppdir)/symboldatabase.o: lib/symboldatabase.cpp lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(libcppdir)/symboldatabase.o: lib/symboldatabase.cpp lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/keywords.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/symboldatabase.cpp
$(libcppdir)/templatesimplifier.o: lib/templatesimplifier.cpp lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h

View File

@ -36,6 +36,7 @@ Highlighter::Highlighter(QTextDocument *parent,
mKeywordFormat.setForeground(mWidgetStyle->keywordColor);
mKeywordFormat.setFontWeight(mWidgetStyle->keywordWeight);
QStringList keywordPatterns;
// TODO: use Keywords::getX()
keywordPatterns << "alignas"
<< "alignof"
<< "asm"

View File

@ -22,6 +22,7 @@
#include "astutils.h"
#include "errorlogger.h"
#include "errortypes.h"
#include "keywords.h"
#include "library.h"
#include "mathlib.h"
#include "path.h"
@ -1387,6 +1388,7 @@ void SymbolDatabase::createSymbolDatabaseEnums()
void SymbolDatabase::createSymbolDatabaseIncompleteVars()
{
// TODO: replace with Keywords::getX()
static const std::unordered_set<std::string> cpp20keywords = {
"alignas",
"alignof",
@ -1476,6 +1478,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
// Skip goto labels
if (Token::simpleMatch(tok->previous(), "goto"))
continue;
// TODO: handle all C/C++ standards
if (cppkeywords.count(tok->str()) > 0)
continue;
if (mSettings->standards.cpp >= Standards::CPP20 && cpp20keywords.count(tok->str()) > 0)
@ -5999,37 +6002,16 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n
//---------------------------------------------------------------------------
namespace {
#define C_KEYWORDS \
"_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex", "_Generic", "_Imaginary", "_Noreturn", \
"_Static_assert", "_Thread_local", "auto", "break", "case", "char", "const", "continue", "default", \
"do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "inline", "int", "long", \
"register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", \
"union", "unsigned", "void", "volatile", "while"
const std::unordered_set<std::string> c_keywords = { C_KEYWORDS, "restrict" };
const std::unordered_set<std::string> cpp_keywords = {
C_KEYWORDS,
"alignas", "alignof", "and", "and_eq", "asm", "bitand", "bitor", "bool", "catch", "char8_t", "char16_t",
"char32_t", "class", "compl", "concept", "consteval", "constexpr", "constinit", "const_cast", "co_await",
"co_return", "co_yield", "decltype",
"delete", "dynamic_cast", "explicit", "export", "false", "friend",
"mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator",
"or", "or_eq", "private", "protected", "public", "reinterpret_cast",
"requires", "static_assert",
"static_cast", "template", "this", "thread_local", "throw",
"true", "try", "typeid", "typename", "using",
"virtual", "wchar_t", "xor", "xor_eq"
};
}
bool SymbolDatabase::isReservedName(const std::string& iName) const
{
if (isCPP())
if (isCPP()) {
static const auto& cpp_keywords = Keywords::getAll(Standards::cppstd_t::CPPLatest);
return cpp_keywords.find(iName) != cpp_keywords.cend();
else
}
else {
static const auto& c_keywords = Keywords::getAll(Standards::cstd_t::CLatest);
return c_keywords.find(iName) != c_keywords.cend();
}
}
nonneg int SymbolDatabase::sizeOfType(const Token *type) const

View File

@ -97,6 +97,7 @@ static const std::unordered_set<std::string> controlFlowKeywords = {
"return"
};
// TODO: replace with Keywords::getX()?
// Another list of keywords
static const std::unordered_set<std::string> baseKeywords = {
"asm",