-
Notifications
You must be signed in to change notification settings - Fork 50
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
base: master
Are you sure you want to change the base?
Conversation
std::string str = ("static_cast<" + DestTypeString + ">").str(); | ||
const Expr *SubExpr = Item->getSubExprAsWritten()->IgnoreImpCasts(); | ||
|
||
if(!isa<ParenExpr>(SubExpr)) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ;
required here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нет, можно обойтись и без ; потому что ; находится в конце блока.
No description provided.