symboldatabase.cpp: use `Keywords` / added TODOs (#4828)
This commit is contained in:
parent
51c5a79150
commit
75619db1d5
2
Makefile
2
Makefile
|
@ -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
|
$(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
|
$(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
|
$(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
|
$(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
|
||||||
|
|
|
@ -36,6 +36,7 @@ Highlighter::Highlighter(QTextDocument *parent,
|
||||||
mKeywordFormat.setForeground(mWidgetStyle->keywordColor);
|
mKeywordFormat.setForeground(mWidgetStyle->keywordColor);
|
||||||
mKeywordFormat.setFontWeight(mWidgetStyle->keywordWeight);
|
mKeywordFormat.setFontWeight(mWidgetStyle->keywordWeight);
|
||||||
QStringList keywordPatterns;
|
QStringList keywordPatterns;
|
||||||
|
// TODO: use Keywords::getX()
|
||||||
keywordPatterns << "alignas"
|
keywordPatterns << "alignas"
|
||||||
<< "alignof"
|
<< "alignof"
|
||||||
<< "asm"
|
<< "asm"
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "astutils.h"
|
#include "astutils.h"
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
#include "errortypes.h"
|
#include "errortypes.h"
|
||||||
|
#include "keywords.h"
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
#include "mathlib.h"
|
#include "mathlib.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
@ -1387,6 +1388,7 @@ void SymbolDatabase::createSymbolDatabaseEnums()
|
||||||
|
|
||||||
void SymbolDatabase::createSymbolDatabaseIncompleteVars()
|
void SymbolDatabase::createSymbolDatabaseIncompleteVars()
|
||||||
{
|
{
|
||||||
|
// TODO: replace with Keywords::getX()
|
||||||
static const std::unordered_set<std::string> cpp20keywords = {
|
static const std::unordered_set<std::string> cpp20keywords = {
|
||||||
"alignas",
|
"alignas",
|
||||||
"alignof",
|
"alignof",
|
||||||
|
@ -1476,6 +1478,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
|
||||||
// Skip goto labels
|
// Skip goto labels
|
||||||
if (Token::simpleMatch(tok->previous(), "goto"))
|
if (Token::simpleMatch(tok->previous(), "goto"))
|
||||||
continue;
|
continue;
|
||||||
|
// TODO: handle all C/C++ standards
|
||||||
if (cppkeywords.count(tok->str()) > 0)
|
if (cppkeywords.count(tok->str()) > 0)
|
||||||
continue;
|
continue;
|
||||||
if (mSettings->standards.cpp >= Standards::CPP20 && cpp20keywords.count(tok->str()) > 0)
|
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
|
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();
|
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();
|
return c_keywords.find(iName) != c_keywords.cend();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nonneg int SymbolDatabase::sizeOfType(const Token *type) const
|
nonneg int SymbolDatabase::sizeOfType(const Token *type) const
|
||||||
|
|
|
@ -97,6 +97,7 @@ static const std::unordered_set<std::string> controlFlowKeywords = {
|
||||||
"return"
|
"return"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: replace with Keywords::getX()?
|
||||||
// Another list of keywords
|
// Another list of keywords
|
||||||
static const std::unordered_set<std::string> baseKeywords = {
|
static const std::unordered_set<std::string> baseKeywords = {
|
||||||
"asm",
|
"asm",
|
||||||
|
|
Loading…
Reference in New Issue