-
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 #30
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,24 @@ using namespace clang::ast_matchers; | |
using namespace clang::tooling; | ||
|
||
class CastCallBack : public MatchFinder::MatchCallback { | ||
private: Rewriter &rewriter; | ||
public: | ||
CastCallBack(Rewriter& rewriter) { | ||
CastCallBack(Rewriter& rewriter_):rewriter(rewriter_) { | ||
// Your code goes here | ||
}; | ||
|
||
void run(const MatchFinder::MatchResult &Result) override { | ||
// Your code goes here | ||
const auto *StyleCastExpr=Result.Nodes.getNodeAs<CStyleCastExpr>("cast"); | ||
auto leftParenLoc=StyleCastExpr->getLParenLoc(); | ||
auto rigthParenLoc=StyleCastExpr->getRParenLoc(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please describe the difference between the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getRParenLos() a special method of the CStyleCastExprclass, this method returns the position where the closing right bracket is located. An object of the CStyleCastExpr class is an indication of a node in the AST tree. |
||
rewriter.RemoveText(leftParenLoc,1); | ||
rewriter.RemoveText(rigthParenLoc,1); | ||
auto &sourceManager=*Result.SourceManager; | ||
auto endLine=Lexer::getLocForEndOfToken(StyleCastExpr->getEndLoc(),0,sourceManager,LangOptions()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please describe the reason of using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
rewriter.InsertText(leftParenLoc,"static_cast<"); | ||
rewriter.InsertText(rigthParenLoc,">("); | ||
rewriter.InsertText(endLine,")"); | ||
} | ||
}; | ||
|
||
|
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.
What if
StyleCastExpr
is a null pointer? How to protect the program from crashing in such cases?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.
add this if(StyleCastExpr==nullptr) { return; }