-
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-1 #29
base: main
Are you sure you want to change the base?
Conversation
|
||
_rewriter.ReplaceText(lParen, 1, "static_cast<"); | ||
_rewriter.ReplaceText(rParen, 1, ">("); | ||
_rewriter.InsertTextAfterToken(castExpr->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 how to change the program code to get the following result:
int main() {
float fooooo;
int i = static_cast<int>(fooooo) ;
return 0;
}
for the origin test.cpp
:
int main() {
float fooooo;
int i = (int) fooooo ;
return 0;
}
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.
Remove the opening bracket from _rewriter.ReplaceText(rParen, 1, ">(");
To add it, getSubExprAsWritten()->getBeginLoc() is usually used to get the initial position of the variable, then "(" is inserted at this token.
// Your code goes here | ||
if (auto castExpr = Result.Nodes.getNodeAs<clang::CStyleCastExpr>("cast")) { | ||
auto lParen = castExpr->getLParenLoc(); | ||
auto rParen = castExpr->getRParenLoc(); |
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 difference between the use of getRParenLoc()
and getSubExprAsWritten()->getBeginLoc()
.
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.
In this case:
getRParenLoc() gets the location of the closing brace before the variable.
getSubExprAsWritten()->getBeginLoc() gets the starting location of the variable, there may be spaces between the closing brace and the variable.
|
|
No description provided.