-
Notifications
You must be signed in to change notification settings - Fork 53
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
Лабораторная работа №3. Феоктистов Андрей. 381906-3 #36
base: main
Are you sure you want to change the base?
Conversation
main.cpp
Outdated
cast_str=("static_cast<"+type+">(").str(); // add left bracket | ||
|
||
myrewriter.InsertText( | ||
Lexer::getLocForEndOfToken( |
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 the reason of using theLexer::getLocForEndOfToken()
function here.
What would be the difference if rewriter.InsertText(styleCastExpr->getEndLoc().getLocOffset(1), ")");
was used here?
What would be the difference if rewriter.InsertTextAfterToken(styleCastExpr->getEndLoc(), ")");
was used 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.
If we use rewriter.InsertText(styleCastExpr->getEndLoc().getLocOffset(1), ")"); then ")" will be inserted immediately after expr + 1(offset) if the variable name is longer than one character we will get wrong result.
i used Lexer::getLocForEndOfToken() to get the position after last token in the line;
Now i see that i could use rewriter.InsertTextAfterToken(expr->getEndLoc(), ")"); instead cause it gives the same result.
main.cpp
Outdated
|
||
myrewriter.InsertText( | ||
Lexer::getLocForEndOfToken( | ||
expr->getSubExprAsWritten()->IgnoreImpCasts()->getEndLoc(), |
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 here getSubExprAsWritten()
and IgnoreImpCasts()
.
What would be the difference with the use of getSubExprAsWritten()->IgnoreImpCasts()
, getSubExpr()->IgnoreImpCasts()
and getSubExprAsWritten()
?
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.
getSubExprAsWritten() retrieves the cast subexpression as it was written in the source code, looking through any implicit casts or other intermediate nodes introduced by semantic analysis.
getSubExpr() retrieves the first cast subexpression and IgnoreImpCasts() skips past any implicit casts which might surround this expression until reaching a fixed point.
So it was no sense to use getSubExprAsWritten() and IgnoreImpCasts(), we can use just getSubExprAsWritten().
But we must use IgnoreImpCasts() with getSubExpr() cause if we will write only getSubExpr() we can get unexpected result.
getSubExpr()->IgnoreImpCasts() and getSubExprAsWritten() will give the same result.
How to prevent changing the C style cast code for a special case - when we want to suppress warnings about unused variables? |
-> To prevent changing the C style cast in this case we can use this check if (expr->getCastKind() == CK_ToVoid) and do nothing if it's returns true. |
No description provided.