Skip to content
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

Пронин И.П. 381806-1 #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

igor-pronin
Copy link

No description provided.

std::string str = ("static_cast<" + DestTypeString + ">").str();
const Expr *SubExpr = Item->getSubExprAsWritten()->IgnoreImpCasts();

if(!isa<ParenExpr>(SubExpr)) {
Copy link
Owner

@eshulankina eshulankina May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this check mean? Please describe examples of when this check returns true and when this check returns false.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта проверка возвращает true или false в зависимости от того, заключено ли текущее выражение в скобки. Пример: int a = (int)f - true; int a = (int)(f) - false.


void run(const MatchFinder::MatchResult &Result) override {
// Your code goes here

const auto *Item = Result.Nodes.getNodeAs<CStyleCastExpr>("cast");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if Item is a null pointer? How to protect the program from crashing in such cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как вариант дописать такую проверку:
if (Item == nullptr)
return;

SourceM,
Result.Context->getLangOpts());

std::string str = ("static_cast<" + DestTypeString + ">").str();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is .str() used here? What happens if we get rid of .str() call?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта функция нужна чтобы вписать type в строку static_cast.

Item->getSubExprAsWritten()->getBeginLoc());

StringRef DestTypeString =
Lexer::getSourceText(CharSourceRange::getTokenRange(Item->getLParenLoc().getLocWithOffset(1),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe why you are using getTokenRange() here.
What is the difference between the getTokenRange() and the getCharRange() method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTokenRange() - возвращает диапазон токенов до начала последнего токена
getCharRange() - возвращает диапазон символов до последнего символа включительно
Допустимо использование обоих вариантов, просто аргументы функций будут различны.

CastCallBack(Rewriter& rewriter) {
// Your code goes here
};
CastCallBack(Rewriter& rewriter) : rewriter_(rewriter) { };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ; required here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет, можно обойтись и без ; потому что ; находится в конце блока.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants