PTHLexer now owns the Token vector.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60136 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp
index 5716d49..5129d58 100644
--- a/lib/Lex/PPLexerChange.cpp
+++ b/lib/Lex/PPLexerChange.cpp
@@ -78,6 +78,16 @@
Lexer *TheLexer = new Lexer(SourceLocation::getFileLoc(FileID, 0), *this);
EnterSourceFileWithLexer(TheLexer, CurDir);
#else
+ if (CurPPLexer || CurTokenLexer)
+ PushIncludeMacroStack();
+
+ CurDirLookup = CurDir;
+ SourceLocation Loc = SourceLocation::getFileLoc(FileID, 0);
+ CurPTHLexer.reset(new PTHLexer(*this, Loc));
+ CurPPLexer = CurPTHLexer.get();
+
+ // Generate the tokens.
+
const llvm::MemoryBuffer* B = getSourceManager().getBuffer(FileID);
// Create a raw lexer.
@@ -89,7 +99,7 @@
L.SetCommentRetentionState(false);
// Lex the file, populating our data structures.
- std::vector<Token>* Tokens = new std::vector<Token>();
+ std::vector<Token>& Tokens = CurPTHLexer->getTokens();
Token Tok;
do {
@@ -101,7 +111,7 @@
else if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) {
// Special processing for #include. Store the '#' token and lex
// the next token.
- Tokens->push_back(Tok);
+ Tokens.push_back(Tok);
L.LexFromRawLexer(Tok);
// Did we see 'include'/'import'/'include_next'?
@@ -116,7 +126,7 @@
K == tok::pp_include_next) {
// Save the 'include' token.
- Tokens->push_back(Tok);
+ Tokens.push_back(Tok);
// Lex the next token as an include string.
L.ParsingPreprocessorDirective = true;
@@ -128,15 +138,7 @@
}
}
}
- while (Tokens->push_back(Tok), Tok.isNot(tok::eof));
-
- if (CurPPLexer || CurTokenLexer)
- PushIncludeMacroStack();
-
- CurDirLookup = CurDir;
- SourceLocation Loc = SourceLocation::getFileLoc(FileID, 0);
- CurPTHLexer.reset(new PTHLexer(*this, Loc, &(*Tokens)[0], Tokens->size()));
- CurPPLexer = CurPTHLexer.get();
+ while (Tokens.push_back(Tok), Tok.isNot(tok::eof));
// Notify the client, if desired, that we are in a new source file.
if (Callbacks) {
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index 21fb983..bc9e714 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -16,16 +16,8 @@
#include "clang/Basic/TokenKinds.h"
using namespace clang;
-PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc,
- const Token *TokArray, unsigned NumTokens)
- : PreprocessorLexer(&pp, fileloc),
- Tokens(TokArray),
- LastTokenIdx(NumTokens - 1),
- CurTokenIdx(0) {
-
- assert(NumTokens >= 1);
- assert(Tokens[LastTokenIdx].is(tok::eof));
-}
+PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc)
+ : PreprocessorLexer(&pp, fileloc), CurTokenIdx(0) {}
Token PTHLexer::GetToken() {
Token Tok = Tokens[CurTokenIdx];
@@ -104,7 +96,8 @@
}
void PTHLexer::setEOF(Token& Tok) {
- Tok = Tokens[LastTokenIdx];
+ assert(!Tokens.empty());
+ Tok = Tokens[Tokens.size()-1];
}
void PTHLexer::DiscardToEndOfLine() {