Add Lexer::IsHashbangAllowed, drop SourceManager::getHashbangBufferID (#18534)

Having this be a single buffer hardcoded in the SourceManager and set
by all clients is silly. SourceFiles with the 'Main' kind are allowed
to have hashbang lines (`#!`), other files are not. And anyone
manually setting up a Lexer can decide for themselves.

No intended behavioral change.
This commit is contained in:
Jordan Rose
2018-08-07 08:25:05 -07:00
committed by GitHub
parent 4aae0bec1e
commit fc9ea1e329
10 changed files with 61 additions and 61 deletions

View File

@@ -506,13 +506,7 @@ static StringRef getSourceToken(unsigned Offset,
MemBuf->getBufferIdentifier());
auto BufId = SM.addNewSourceBuffer(std::move(MemBufRef));
SourceLoc Loc = SM.getLocForOffset(BufId, Offset);
// Use fake language options; language options only affect validity
// and the exact token produced.
LangOptions FakeLangOpts;
Lexer L(FakeLangOpts, SM, BufId, nullptr, /*InSILMode=*/ false,
CommentRetentionMode::ReturnAsTokens);
return L.getTokenAt(Loc).getText();
return Lexer::getTokenAtLocation(SM, Loc).getText();
}
static llvm::Optional<unsigned>