summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/Lex/Lexer.cpp37
-rw-r--r--clang/Lex/Preprocessor.cpp35
-rw-r--r--clang/include/clang/Lex/Lexer.h11
-rw-r--r--clang/include/clang/Lex/Preprocessor.h6
4 files changed, 44 insertions, 45 deletions
diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp
index 2a1bcc0248f..7b4cbd7962d 100644
--- a/clang/Lex/Lexer.cpp
+++ b/clang/Lex/Lexer.cpp
@@ -39,8 +39,7 @@ static void InitCharacterInfo();
Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp,
const char *BufStart, const char *BufEnd)
- : BufferPtr(BufStart ? BufStart : File->getBufferStart()),
- BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
+ : BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
InputFile(File), CurFileID(fileid), PP(pp), Features(PP.getLangOptions()) {
Is_PragmaLexer = false;
IsMainFile = false;
@@ -49,7 +48,9 @@ Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp,
assert(BufferEnd[0] == 0 &&
"We assume that the input buffer has a null character at the end"
" to simplify lexing!");
-
+
+ BufferPtr = BufStart ? BufStart : File->getBufferStart();
+
// Start of the file is a start of line.
IsAtStartOfLine = true;
@@ -922,6 +923,36 @@ void Lexer::LexEndOfFile(LexerToken &Result, const char *CurPtr) {
PP.HandleEndOfFile(Result);
}
+/// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
+/// the specified lexer will return a tok::l_paren token, 0 if it is something
+/// else and 2 if there are no more tokens in the buffer controlled by the
+/// lexer.
+unsigned Lexer::isNextPPTokenLParen() {
+ assert(!LexingRawMode && "How can we expand a macro from a skipping buffer?");
+
+ // Switch to 'skipping' mode. This will ensure that we can lex a token
+ // without emitting diagnostics, disables macro expansion, and will cause EOF
+ // to return an EOF token instead of popping the include stack.
+ LexingRawMode = true;
+
+ // Save state that can be changed while lexing so that we can restore it.
+ const char *TmpBufferPtr = BufferPtr;
+
+ LexerToken Tok;
+ Tok.StartToken();
+ LexTokenInternal(Tok);
+
+ // Restore state that may have changed.
+ BufferPtr = TmpBufferPtr;
+
+ // Restore the lexer back to non-skipping mode.
+ LexingRawMode = false;
+
+ if (Tok.getKind() == tok::eof)
+ return 2;
+ return Tok.getKind() == tok::l_paren;
+}
+
/// LexTokenInternal - This implements a simple C family lexer. It is an
/// extremely performance critical piece of code. This assumes that the buffer
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp
index da8b9d15114..f316c67b3c3 100644
--- a/clang/Lex/Preprocessor.cpp
+++ b/clang/Lex/Preprocessor.cpp
@@ -506,37 +506,6 @@ static bool isTrivialSingleTokenExpansion(const MacroInfo *MI,
return true;
}
-/// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
-/// the specified lexer will return a tok::l_paren token, 0 if it is something
-/// else and 2 if there are no more tokens in the buffer controlled by the
-/// lexer.
-unsigned Preprocessor::isNextPPTokenLParen(Lexer *L) {
- assert(!L->LexingRawMode &&
- "How can we expand a macro from a skipping buffer?");
-
- // Set the lexer to 'skipping' mode. This will ensure that we can lex a token
- // without emitting diagnostics, disables macro expansion, and will cause EOF
- // to return an EOF token instead of popping the include stack.
- L->LexingRawMode = true;
-
- // Save state that can be changed while lexing so that we can restore it.
- const char *BufferPtr = L->BufferPtr;
-
- LexerToken Tok;
- Tok.StartToken();
- L->LexTokenInternal(Tok);
-
- // Restore state that may have changed.
- L->BufferPtr = BufferPtr;
-
- // Restore the lexer back to non-skipping mode.
- L->LexingRawMode = false;
-
- if (Tok.getKind() == tok::eof)
- return 2;
- return Tok.getKind() == tok::l_paren;
-}
-
/// isNextPPTokenLParen - Determine whether the next preprocessor token to be
/// lexed is a '('. If so, consume the token and return true, if not, this
@@ -545,7 +514,7 @@ bool Preprocessor::isNextPPTokenLParen() {
// Do some quick tests for rejection cases.
unsigned Val;
if (CurLexer)
- Val = isNextPPTokenLParen(CurLexer);
+ Val = CurLexer->isNextPPTokenLParen();
else
Val = CurMacroExpander->isNextTokenLParen();
@@ -555,7 +524,7 @@ bool Preprocessor::isNextPPTokenLParen() {
for (unsigned i = IncludeMacroStack.size(); Val == 2 && i != 0; --i) {
IncludeStackInfo &Entry = IncludeMacroStack[i-1];
if (Entry.TheLexer)
- Val = isNextPPTokenLParen(Entry.TheLexer);
+ Val = Entry.TheLexer->isNextPPTokenLParen();
else
Val = Entry.TheMacroExpander->isNextTokenLParen();
}
diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h
index ffa4cd2dbea..6de701c02a2 100644
--- a/clang/include/clang/Lex/Lexer.h
+++ b/clang/include/clang/Lex/Lexer.h
@@ -86,8 +86,9 @@ class Lexer {
bool LexingRawMode;
//===--------------------------------------------------------------------===//
- // Context that changes as the file is lexed. NOTE: any state that mutates as
- // the file is lexed should be added to Preprocessor::isNextPPTokenLParen.
+ // Context that changes as the file is lexed.
+ // NOTE: any state that mutates when in raw mode must have save/restore code
+ // in Lexer::isNextPPTokenLParen.
// BufferPtr - Current pointer into the buffer. This is the next character
// to be lexed.
@@ -191,7 +192,11 @@ private:
BufferPtr = TokEnd;
}
-
+ /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
+ /// tok::l_paren token, 0 if it is something else and 2 if there are no more
+ /// tokens in the buffer controlled by this lexer.
+ unsigned isNextPPTokenLParen();
+
//===--------------------------------------------------------------------===//
// Lexer character reading interfaces.
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 83b2f07f40d..be07b81b265 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -466,12 +466,6 @@ private:
/// the macro should not be expanded return true, otherwise return false.
bool HandleMacroExpandedIdentifier(LexerToken &Tok, MacroInfo *MI);
- /// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from
- /// the specified lexer will return a tok::l_paren token, 0 if it is something
- /// else and 2 if there are no more tokens in the buffer controlled by the
- /// lexer.
- unsigned isNextPPTokenLParen(Lexer *L);
-
/// isNextPPTokenLParen - Determine whether the next preprocessor token to be
/// lexed is a '('. If so, consume the token and return true, if not, this
/// method should have no observable side-effect on the lexed tokens.
OpenPOWER on IntegriCloud