-
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?
Лабораторная работа №3. Зайцев Александр 381906-1 #30
Conversation
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Please describe the reason of using theLexer::getLocForEndOfToken()
function here.
What would be the difference if rewriter.InsertText(styleCastExpr->getEndLoc().getLocOffset(1), ")");
was used here?
What would be the difference if rewriter.InsertTextAfterToken(styleCastExpr->getEndLoc(), ")");
was used here?
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.
- get::LocForEndOfToken() . Computes the source location just past the end of the token at this source location.
- rewriter.InsertText(styleCastExpr->getEndLoc().getLocOffset(1),")"); give us position right after (cast) and getEndLoc().getLocOffset(1) shifts this position by one to the right. If the variable declared in main has a name of two or more symbol and use rewriter.InsertText(styleCastExpr->getEndLoc().getLocOffset(1),")"); . like main we will get m)ain .
3)rewriter.InsertTextAfterToken(styleCastExpr->getEndLoc(),")"); . If use this we will get the same position and output but different way.
// 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 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.
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.
If call the getSubExprAsWritten() method, it will return the desired tree node, ignoring the auxiliary ImplicitCastExpr nodes.
getBeginLoc() is used here to get the start position of this variable. But need to separately call the method of removing the closing right bracket rewriter_.Remove Text(styleCastExpr->getRParenLoc(), 1); .
The main difference is that when using getRParenLoc(), the search for the desired position is carried out using a closing parenthesis, and when using getSubExprAsWritten(), it is carried out using a variable for which the CStyleCast transformation was called.
|
// Your code goes here | ||
}; | ||
|
||
void run(const MatchFinder::MatchResult &Result) override { | ||
// Your code goes here | ||
const auto *StyleCastExpr=Result.Nodes.getNodeAs<CStyleCastExpr>("cast"); |
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; }
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?
|
How to prevent changing the C style cast code in macros? |
No description provided.