-
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 #35
base: main
Are you sure you want to change the base?
Conversation
auto endLoc = cStyleCExpr->getEndLoc(); | ||
|
||
rewriter.ReplaceText(lPloc, 1, "static_cast<"); | ||
rewriter.ReplaceText(rPloc, 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 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.
Вместо строки:
rewriter.ReplaceText(rPloc, 1, ">(");
сделать строку
rewriter.ReplaceText(rPloc, 1, ">");
далее найти subexpr, найти его начало (первый токен) и в полученное расположение вставить "(", то есть выполнить команду:
rewriter.InsertText(cStyleCExpr->getSubExprAsWritten()->getBeginLoc(), "(");
|
if (cStyleCExpr) добавить в операторе if условие проверки на макрос, если макрос - то ничего не делать !(cStyleCExpr->getExprLoc().isMacroID())
if (cStyleCExpr) добавить условие проверки на тип преобразования, если он - void, то ничего не делать cStyleCExpr->getCastKind() != CK_ToVoid
rewriter.InsertText(cStyleCExpr->getSubExprAsWritten()->getBeginLoc(), "(");
rewriter.InsertTextAfterToken(endLoc, ")"); добавить проверку условия принадлежности subexpr классу ParenExpr (принадлежность этому классу означает, что выражение обернуто в скобки). Если не принадлежит - выполнить добавление скобок вначале выражения и в конце if(!isa<ParenExpr>(cStyleCExpr->getSubExprAsWritten())) {
rewriter.InsertText(cStyleCExpr->getSubExprAsWritten()->getBeginLoc(), "(");
rewriter.InsertTextAfterToken(endLoc, ")");
} |
No description provided.