Skip to content

Instantly share code, notes, and snippets.

@jaredhoberock
Created August 18, 2023 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredhoberock/c904f36096dc02498507ad010ffe3f5d to your computer and use it in GitHub Desktop.
Save jaredhoberock/c904f36096dc02498507ad010ffe3f5d to your computer and use it in GitHub Desktop.
Lexing for delete
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