Created
August 18, 2023 04:58
-
-
Save jaredhoberock/c904f36096dc02498507ad010ffe3f5d to your computer and use it in GitHub Desktop.
Lexing for delete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SourceLocation location_of_delete_keyword(FunctionDecl* FD, SourceManager& SM, const LangOptions& LO) | |
{ | |
// getSourceRange() of a CXXMethodDecl seems to include the "= delete" | |
if(isa<CXXMethodDecl>(FD)) return FD->getSourceRange().getEnd(); | |
// we need to lex to find the end of "delete" for functions | |
// that are not methods because their SourceRange omits | |
// the trailing "= delete" | |
SourceLocation loc = FD->getBeginLoc(); | |
SourceLocation result = FD->getEndLoc(); | |
while(true) | |
{ | |
Optional<Token> token = Lexer::findNextToken(loc, SM, LO); | |
if(not token) | |
{ | |
break; | |
} | |
if(token->is(tok::eof)) | |
{ | |
break; | |
} | |
if(Lexer::getSpelling(*token, SM, LO) == "delete") | |
{ | |
result = token->getLastLoc(); | |
break; | |
} | |
loc = token->getLocation().getLocWithOffset(token->getLength()); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment