PTHLexer.h revision bc0f6bc0391ecdff331885cdc769c20b2cb628a6
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 72 /// getSourceLocation - Return a source location for the token in 73 /// the current file. 74 SourceLocation getSourceLocation() { return GetToken().getLocation(); } 75 76private: 77 78 /// AtLastToken - Returns true if the PTHLexer is at the last token. 79 bool AtLastToken() { 80 Token T = GetToken(); 81 return T.is(tok::eof) ? EofToken = T, true : false; 82 } 83 84 /// GetToken - Returns the next token. This method does not advance the 85 /// PTHLexer to the next token. 86 Token GetToken(); 87 88 /// AdvanceToken - Advances the PTHLexer to the next token. 89 void AdvanceToken() { ++CurTokenIdx; NeedsFetching = true; } 90 91 bool LexEndOfFile(Token &Result); 92}; 93 94} // end namespace clang 95 96#endif 97