PTHLexer.h revision 0c6a77bc1f52f282a969538f139ebde429076ed3
1//===--- PTHLexer.h - Lexer based on Pre-tokenized input --------*- C++ -*-===// 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 defines the PTHLexer interface. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_PTHLEXER_H 15#define LLVM_CLANG_PTHLEXER_H 16 17#include "clang/Lex/PreprocessorLexer.h" 18#include <vector> 19 20namespace clang { 21 22class PTHManager; 23 24class PTHLexer : public PreprocessorLexer { 25 /// TokBuf - Buffer from PTH file containing raw token data. 26 const char* TokBuf; 27 28 /// CurTokenIdx - This is the index of the next token that Lex will return. 29 unsigned CurTokenIdx; 30 31 PTHLexer(const PTHLexer&); // DO NOT IMPLEMENT 32 void operator=(const PTHLexer&); // DO NOT IMPLEMENT 33 34 /// ReadToken - Used by PTHLexer to read tokens TokBuf. 35 void ReadToken(Token& T); 36 37 /// PTHMgr - The PTHManager object that created this PTHLexer. 38 PTHManager& PTHMgr; 39 40 Token LastFetched; 41 Token EofToken; 42 bool NeedsFetching; 43 44public: 45 46 /// Create a PTHLexer for the specified token stream. 47 PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D, 48 PTHManager& PM); 49 50 ~PTHLexer() {} 51 52 /// Lex - Return the next token. 53 void Lex(Token &Tok); 54 55 void setEOF(Token &Tok); 56 57 /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an 58 /// uninterpreted string. This switches the lexer out of directive mode. 59 void DiscardToEndOfLine(); 60 61 /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a 62 /// tok::l_paren token, 0 if it is something else and 2 if there are no more 63 /// tokens controlled by this lexer. 64 unsigned isNextPPTokenLParen() { 65 return AtLastToken() ? 2 : GetToken().is(tok::l_paren); 66 } 67 68 /// IndirectLex - An indirect call to 'Lex' that can be invoked via 69 /// the PreprocessorLexer interface. 70 void IndirectLex(Token &Result) { Lex(Result); } 71 72private: 73 74 /// AtLastToken - Returns true if the PTHLexer is at the last token. 75 bool AtLastToken() { 76 Token T = GetToken(); 77 return T.is(tok::eof) ? EofToken = T, true : false; 78 } 79 80 /// GetToken - Returns the next token. This method does not advance the 81 /// PTHLexer to the next token. 82 Token GetToken(); 83 84 /// AdvanceToken - Advances the PTHLexer to the next token. 85 void AdvanceToken() { ++CurTokenIdx; NeedsFetching = true; } 86 87 bool LexEndOfFile(Token &Result); 88}; 89 90} // end namespace clang 91 92#endif 93