Telegram Group & Telegram Channel
#compiler

[Часть 2/2]
Как работает статический анализ кода? Обзор clang-tidy 🧹🧹🧹

В коде, который реагирует на найденную ноду, нужно определить текст warning-a:

  const VarDecl *D = nullptr;
StringRef Msg;
bool InsertInlineKeyword = false;

if ((D = Result.Nodes.getNodeAs<VarDecl>("non-inline-var-definition"))) {
Msg = "global constant %0 should be marked as 'inline'";
InsertInlineKeyword = true;
} else {
D = Result.Nodes.getNodeAs<VarDecl>("extern-var-declaration");
Msg = "global constant %0 should be converted to C++17 'inline variable'";
}

Если мы увидели, что переменная объявлена не в хидере, то ничего не делаем, возвращаем из функции (на уровне AST Matchers это пока нельзя ловить).

Теперь можно вывести красивый warning в месте объявления переменной.
Если у нас случай с определением не-inline переменной, то заодно можно поправить исходник, приписав "inline " перед объявлением переменной (во время работы clang-tidy поправит исходник):

  DiagnosticBuilder Diag = diag(D->getLocation(), Msg) << D;
if (InsertInlineKeyword)
Diag << FixItHint::CreateInsertion(D->getBeginLoc(), "inline ");

Теперь вы знаете, как примерно работает статический анализ кода 🙂



group-telegram.com/cxx95/52
Create:
Last Update:

#compiler

[Часть 2/2]
Как работает статический анализ кода? Обзор clang-tidy 🧹🧹🧹

В коде, который реагирует на найденную ноду, нужно определить текст warning-a:

  const VarDecl *D = nullptr;
StringRef Msg;
bool InsertInlineKeyword = false;

if ((D = Result.Nodes.getNodeAs<VarDecl>("non-inline-var-definition"))) {
Msg = "global constant %0 should be marked as 'inline'";
InsertInlineKeyword = true;
} else {
D = Result.Nodes.getNodeAs<VarDecl>("extern-var-declaration");
Msg = "global constant %0 should be converted to C++17 'inline variable'";
}

Если мы увидели, что переменная объявлена не в хидере, то ничего не делаем, возвращаем из функции (на уровне AST Matchers это пока нельзя ловить).

Теперь можно вывести красивый warning в месте объявления переменной.
Если у нас случай с определением не-inline переменной, то заодно можно поправить исходник, приписав "inline " перед объявлением переменной (во время работы clang-tidy поправит исходник):

  DiagnosticBuilder Diag = diag(D->getLocation(), Msg) << D;
if (InsertInlineKeyword)
Diag << FixItHint::CreateInsertion(D->getBeginLoc(), "inline ");

Теперь вы знаете, как примерно работает статический анализ кода 🙂

BY C++95


Warning: Undefined variable $i in /var/www/group-telegram/post.php on line 260

Share with your friend now:
group-telegram.com/cxx95/52

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

Multiple pro-Kremlin media figures circulated the post's false claims, including prominent Russian journalist Vladimir Soloviev and the state-controlled Russian outlet RT, according to the DFR Lab's report. The SC urges the public to refer to the SC’s I nvestor Alert List before investing. The list contains details of unauthorised websites, investment products, companies and individuals. Members of the public who suspect that they have been approached by unauthorised firms or individuals offering schemes that promise unrealistic returns As a result, the pandemic saw many newcomers to Telegram, including prominent anti-vaccine activists who used the app's hands-off approach to share false information on shots, a study from the Institute for Strategic Dialogue shows. Recently, Durav wrote on his Telegram channel that users' right to privacy, in light of the war in Ukraine, is "sacred, now more than ever." Stocks closed in the red Friday as investors weighed upbeat remarks from Russian President Vladimir Putin about diplomatic discussions with Ukraine against a weaker-than-expected print on U.S. consumer sentiment.
from us


Telegram C++95
FROM American