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

Гущин А.А. 381806-3 #42

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

Conversation

ArtyomGi
Copy link

No description provided.

bool FnToFnCast =
isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten);

if (CastExpr->getCastKind() == CK_NoOp && !FnToFnCast &&
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 what this check does.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь проверка на приведение к тому же типу. CastExpr->getCastKind() == CK_NoOp означает, что приведение не влияет на сам тип, а только на спецификаторы типов и noexcept.
!FnToFnCast проверяет на то, что приведение не является приведением функции к функции. Такие приведения могут быть нужны, чтобы явно разрешать перегрузки функций.
SourceTypeAsWritten == DestTypeAsWritten проверяем, что source и destination типы совпадают. По-хорошему такое приведение нужно убирать, так как оно избыточное, но в данном случае сделал просто return

return;
}

if (!match(expr(hasAncestor(linkageSpecDecl())), *CastExpr, *Result.Context)
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 what this check does.

Copy link
Author

@ArtyomGi ArtyomGi May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это проверка на extern "C" блоки. Если приведение находится в таком блоке, то его не нужно заменять


SourceManager &SM = *Result.SourceManager;

if (SM.getFilename(SM.getSpellingLoc(CastExpr->getBeginLoc())).endswith(".c"))
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 what this check does.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверка на расширение файла, в котором находится приведение. Если мы делаем проход и у файла оказалось расширение .c, это означает, что проверяемое приведение находится в файле языка C. Такие приведения заменять не нужно.

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