mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user