blob: e9d6d4794f9dc2ce87aeb900658a4da5ba978402 [file] [log] [blame]
Ted Kremenek274b2082008-11-12 21:37:15 +00001//===--- PTHLexer.cpp - Lex from a token stream ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PTHLexer interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Lex/PTHLexer.h"
15#include "clang/Lex/Preprocessor.h"
Ted Kremenek274b2082008-11-12 21:37:15 +000016#include "clang/Basic/TokenKinds.h"
Ted Kremenek274b2082008-11-12 21:37:15 +000017using namespace clang;
18
19PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc,
20 const Token *TokArray, unsigned NumToks)
Ted Kremenek41938c82008-11-19 21:57:25 +000021 : PreprocessorLexer(&pp, fileloc), FileLoc(fileloc),
22 Tokens(TokArray), NumTokens(NumToks), CurToken(0) {
Ted Kremenek274b2082008-11-12 21:37:15 +000023
24 assert (Tokens[NumTokens-1].is(tok::eof));
25 --NumTokens;
26
27 LexingRawMode = false;
28 ParsingPreprocessorDirective = false;
29 ParsingFilename = false;
30}
31
32void PTHLexer::Lex(Token& Tok) {
33
34 if (CurToken == NumTokens) {
35 // If we hit the end of the file while parsing a preprocessor directive,
36 // end the preprocessor directive first. The next token returned will
37 // then be the end of file.
38 // OR
39 // If we are in raw mode, return this event as an EOF token. Let the caller
40 // that put us in raw mode handle the event.
41 if (ParsingPreprocessorDirective || LexingRawMode) {
42 // Done parsing the "line".
43 ParsingPreprocessorDirective = false;
44 Tok = Tokens[CurToken]; // not an out-of-bound access
45 // FIXME: eom handling?
46 }
47 else
Ted Kremenekd6a2e7d2008-11-12 23:13:54 +000048 PP->HandleEndOfFile(Tok, false);
Ted Kremenek274b2082008-11-12 21:37:15 +000049
50 return;
51 }
52
53 Tok = Tokens[CurToken];
54
55 if (ParsingPreprocessorDirective && Tok.isAtStartOfLine()) {
56 ParsingPreprocessorDirective = false; // Done parsing the "line".
57 MIOpt.ReadToken();
58 // FIXME: Need to replicate:
59 // FormTokenWithChars(Tok, CurPtr, tok::eom);
60 Tok.setKind(tok::eom);
61 return;
62 }
63 else // Otherwise, advance to the next token.
64 ++CurToken;
65
66 if (Tok.isAtStartOfLine() && Tok.is(tok::hash) && !LexingRawMode) {
Ted Kremenekd6a2e7d2008-11-12 23:13:54 +000067 PP->HandleDirective(Tok);
68 PP->Lex(Tok);
Ted Kremenek274b2082008-11-12 21:37:15 +000069 return;
70 }
71
72 MIOpt.ReadToken();
73}
74
75void PTHLexer::setEOF(Token& Tok) {
76 Tok = Tokens[NumTokens]; // NumTokens is already adjusted, so this isn't
77 // an overflow.
78}
Ted Kremenek17ff58a2008-11-19 22:21:33 +000079
80void PTHLexer::DiscardToEndOfLine() {
81 assert(ParsingPreprocessorDirective && ParsingFilename == false &&
82 "Must be in a preprocessing directive!");
Ted Kremenek17ff58a2008-11-19 22:21:33 +000083 assert (0 && "Not implemented.");
84}
Ted Kremenek2f1c0242008-11-19 22:42:26 +000085
86unsigned PTHLexer::isNextPPTokenLParen() {
87 assert (0 && "Not implemented.");
88 return 0;
89}
90