Skip to content

Commit

Permalink
[Lexer] Remove the public Lexer constructor that accepts a StringRef.
Browse files Browse the repository at this point in the history
Replace uses of it with the newly introduced constructor that accepts a buffer ID.
The StringRef constructor was rather unsafe since it had the implicit requirement that the StringRef
was null-terminated.

Swift SVN r6942
  • Loading branch information
akyrtzi committed Aug 6, 2013
1 parent 4e297d0 commit 4908da8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
6 changes: 0 additions & 6 deletions include/swift/Parse/Lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ class Lexer {
void primeLexer();

public:
Lexer(llvm::StringRef Buffer, SourceManager &SourceMgr,
DiagnosticEngine *Diags, bool InSILMode, bool KeepComments = false)
: Lexer(SourceMgr, Buffer, Diags, Buffer.begin(), InSILMode,
KeepComments, /*Prime=*/true) {
}

Lexer(SourceManager &SourceMgr, unsigned BufferID,
DiagnosticEngine *Diags, bool InSILMode, bool KeepComments = false,
unsigned Offset = 0, unsigned EndOffset = 0);
Expand Down
5 changes: 2 additions & 3 deletions lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,8 @@ Parser::Parser(Lexer *Lex, TranslationUnit *TU,
Parser::Parser(unsigned BufferID, TranslationUnit *TU,
bool IsMainModule, SILParserState *SIL,
PersistentParserState *PersistentState)
: Parser(new Lexer(TU->getASTContext().SourceMgr
->getMemoryBuffer(BufferID)->getBuffer(),
TU->getASTContext().SourceMgr, &TU->getASTContext().Diags,
: Parser(new Lexer(TU->getASTContext().SourceMgr, BufferID,
&TU->getASTContext().Diags,
/*InSILMode=*/SIL != nullptr, /*KeepComments=*/false),
TU, TU->getASTContext().Diags, SIL, PersistentState) {
this->IsMainModule = IsMainModule;
Expand Down
8 changes: 4 additions & 4 deletions tools/swift/Immediate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,10 @@ class REPLEnvironment {
case REPLInputKind::REPLDirective: {
auto Buffer =
llvm::MemoryBuffer::getMemBufferCopy(Line, "<REPL Input>");
TU->getASTContext().SourceMgr->AddNewSourceBuffer(Buffer,
llvm::SMLoc());
Lexer L(Buffer->getBuffer(), CI.getSourceMgr(), nullptr,
false /*not SIL*/);
unsigned BufferID =
TU->getASTContext().SourceMgr->AddNewSourceBuffer(Buffer,
llvm::SMLoc());
Lexer L(CI.getSourceMgr(), BufferID, nullptr, false /*not SIL*/);
Token Tok;
L.lex(Tok);
assert(Tok.is(tok::colon));
Expand Down
4 changes: 1 addition & 3 deletions unittests/Parse/LexerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class LexerTest : public ::testing::Test {
public:

std::vector<Token> tokenizeAndKeepEOF(unsigned BufferID) {
const llvm::MemoryBuffer *Buffer = SourceMgr->getMemoryBuffer(BufferID);
Lexer L(Buffer->getBuffer(), SourceMgr, /*Diags=*/nullptr,
/*InSILMode=*/false);
Lexer L(SourceMgr, BufferID, /*Diags=*/nullptr, /*InSILMode=*/false);
std::vector<Token> Tokens;
do {
Tokens.emplace_back();
Expand Down

0 comments on commit 4908da8

Please sign in to comment.