summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PTHLexer.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-11-12 21:37:15 +0000
committerTed Kremenek <kremenek@apple.com>2008-11-12 21:37:15 +0000
commit7cd62457c4d9c2416ef1993577edaf6e78720a88 (patch)
tree728f212a61b70c4504cdccec56b668c16092e618 /clang/lib/Lex/PTHLexer.cpp
parent3a460b11063dc5cef879e9aed6a7d15e1a8ae1db (diff)
downloadbcm5719-llvm-7cd62457c4d9c2416ef1993577edaf6e78720a88.tar.gz
bcm5719-llvm-7cd62457c4d9c2416ef1993577edaf6e78720a88.zip
Add skeleton for PTH lexer.
llvm-svn: 59169
Diffstat (limited to 'clang/lib/Lex/PTHLexer.cpp')
-rw-r--r--clang/lib/Lex/PTHLexer.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp
new file mode 100644
index 00000000000..e1b392068c0
--- /dev/null
+++ b/clang/lib/Lex/PTHLexer.cpp
@@ -0,0 +1,79 @@
+//===--- PTHLexer.cpp - Lex from a token stream ---------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the PTHLexer interface.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Lex/PTHLexer.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
+#include "clang/Basic/TokenKinds.h"
+
+using namespace clang;
+
+PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc,
+ const Token *TokArray, unsigned NumToks)
+ : PP(pp), FileLoc(fileloc), Tokens(TokArray), NumTokens(NumToks), CurToken(0){
+
+ assert (Tokens[NumTokens-1].is(tok::eof));
+ --NumTokens;
+
+ LexingRawMode = false;
+ ParsingPreprocessorDirective = false;
+ ParsingFilename = false;
+}
+
+void PTHLexer::Lex(Token& Tok) {
+
+ if (CurToken == NumTokens) {
+ // If we hit the end of the file while parsing a preprocessor directive,
+ // end the preprocessor directive first. The next token returned will
+ // then be the end of file.
+ // OR
+ // If we are in raw mode, return this event as an EOF token. Let the caller
+ // that put us in raw mode handle the event.
+ if (ParsingPreprocessorDirective || LexingRawMode) {
+ // Done parsing the "line".
+ ParsingPreprocessorDirective = false;
+ Tok = Tokens[CurToken]; // not an out-of-bound access
+ // FIXME: eom handling?
+ }
+ else
+ PP.HandleEndOfFile(Tok, false);
+
+ return;
+ }
+
+ Tok = Tokens[CurToken];
+
+ if (ParsingPreprocessorDirective && Tok.isAtStartOfLine()) {
+ ParsingPreprocessorDirective = false; // Done parsing the "line".
+ MIOpt.ReadToken();
+ // FIXME: Need to replicate:
+ // FormTokenWithChars(Tok, CurPtr, tok::eom);
+ Tok.setKind(tok::eom);
+ return;
+ }
+ else // Otherwise, advance to the next token.
+ ++CurToken;
+
+ if (Tok.isAtStartOfLine() && Tok.is(tok::hash) && !LexingRawMode) {
+ PP.HandleDirective(Tok);
+ PP.Lex(Tok);
+ return;
+ }
+
+ MIOpt.ReadToken();
+}
+
+void PTHLexer::setEOF(Token& Tok) {
+ Tok = Tokens[NumTokens]; // NumTokens is already adjusted, so this isn't
+ // an overflow.
+}
OpenPOWER on IntegriCloud