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

Лабораторная работа №3. Куклин Андрей. 381906-3 #35

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

Conversation

AddMe-pls
Copy link

No description provided.

auto endLoc = cStyleCExpr->getEndLoc();

rewriter.ReplaceText(lPloc, 1, "static_cast<");
rewriter.ReplaceText(rPloc, 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 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;

}

Copy link
Author

@AddMe-pls AddMe-pls May 28, 2022

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(), "(");

@ElizJogar
Copy link
Owner

  • How to prevent changing the C style cast code in macros?
  • How to prevent changing the C style cast code for a special case - when we want to suppress warnings about unused variables?
  • How to prevent parentheses from being added if they are already present in the (int)(f) code?

@AddMe-pls
Copy link
Author

  1. How to prevent changing the C style cast code in macros?
    В строку
if (cStyleCExpr) 

добавить в операторе if условие проверки на макрос, если макрос - то ничего не делать

!(cStyleCExpr->getExprLoc().isMacroID())
  1. How to prevent changing the C style cast code for a special case - when we want to suppress warnings about unused variables?
    В строку
if (cStyleCExpr) 

добавить условие проверки на тип преобразования, если он - void, то ничего не делать

cStyleCExpr->getCastKind() != CK_ToVoid
  1. How to prevent parentheses from being added if they are already present in the (int)(f) code?
    Перед операциями
rewriter.InsertText(cStyleCExpr->getSubExprAsWritten()->getBeginLoc(), "(");
rewriter.InsertTextAfterToken(endLoc, ")");

добавить проверку условия принадлежности subexpr классу ParenExpr (принадлежность этому классу означает, что выражение обернуто в скобки). Если не принадлежит - выполнить добавление скобок вначале выражения и в конце

if(!isa<ParenExpr>(cStyleCExpr->getSubExprAsWritten())) {
  rewriter.InsertText(cStyleCExpr->getSubExprAsWritten()->getBeginLoc(), "(");
  rewriter.InsertTextAfterToken(endLoc, ")");
}

@AddMe-pls AddMe-pls requested a review from ElizJogar May 28, 2022 11:47
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