From c7974267e0e78e6c5c39358fc35cb34eb2199e0d Mon Sep 17 00:00:00 2001 From: Oleksandr Labetskyi Date: Wed, 22 May 2024 18:47:27 +0300 Subject: [PATCH] First draft --- lib/cppcheck.cpp | 2 +- lib/standards.h | 2 +- lib/tokenlist.cpp | 10 +++++++++- lib/tokenlist.h | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 60eb88951d2..f22e999ac98 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -643,7 +643,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string if (mUnusedFunctionsCheck && mSettings.useSingleJob() && mSettings.buildDir.empty()) { // this is not a real source file - we just want to tokenize it. treat it as C anyways as the language needs to be determined. Tokenizer tokenizer(mSettings, *this); - tokenizer.list.setLang(Standards::Language::C); + tokenizer.list.setLang(Standards::Language::Markup); if (fileStream) { tokenizer.list.createTokens(*fileStream, filename); } diff --git a/lib/standards.h b/lib/standards.h index 34d1882a067..478333b7267 100644 --- a/lib/standards.h +++ b/lib/standards.h @@ -34,7 +34,7 @@ * This struct contains all possible standards that cppcheck recognize. */ struct Standards { - enum Language { None, C, CPP }; + enum Language { None, C, CPP, Markup }; /** C code standard */ enum cstd_t { C89, C99, C11, C17, C23, CLatest = C23 } c = CLatest; diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index fae6e123fbf..9acb2df1d46 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -2190,10 +2190,18 @@ bool TokenList::isCPP() const return mLang == Standards::Language::CPP; } +bool TokenList::isMarkup() const +{ + return mLang == Standards::Language::Markup; +} + void TokenList::setLang(Standards::Language lang) { ASSERT_LANG(lang != Standards::Language::None); - ASSERT_LANG(mLang == Standards::Language::None); + //ASSERT_LANG(mLang == Standards::Language::None); + /* OL: We should have an ability to change between languages when we have markup inside c++ project + * which we treat as C + */ mLang = lang; } diff --git a/lib/tokenlist.h b/lib/tokenlist.h index c03cf3b6382..5f8f999b034 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -68,6 +68,9 @@ class CPPCHECKLIB TokenList { /** @return true if the code is C++ */ bool isCPP() const; + /** @return true if the code is a Markup language */ + bool isMarkup() const; + void setLang(Standards::Language lang); /**