PTHLexer.h revision 59d08cb672136322375e5400578ee1fbd0947de2
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 /// CurPtr - Pointer into current offset of the token buffer where 29 /// the next token will be read. 30 const char* CurPtr; 31 32 /// LastHashTokPtr - Pointer into TokBuf of the last processed '#' 33 /// token that appears at the start of a line. 34 const char* LastHashTokPtr; 35 36 /// PPCond - Pointer to a side table in the PTH file that provides a 37 /// a consise summary of the preproccessor conditional block structure. 38 /// This is used to perform quick skipping of conditional blocks. 39 const char* PPCond; 40 41 /// CurPPCondPtr - Pointer inside PPCond that refers to the next entry 42 /// to process when doing quick skipping of preprocessor blocks. 43 const char* CurPPCondPtr; 44 45 PTHLexer(const PTHLexer&); // DO NOT IMPLEMENT 46 void operator=(const PTHLexer&); // DO NOT IMPLEMENT 47 48 /// ReadToken - Used by PTHLexer to read tokens TokBuf. 49 void ReadToken(Token& T); 50 51 /// PTHMgr - The PTHManager object that created this PTHLexer. 52 PTHManager& PTHMgr; 53 54 Token EofToken; 55 56public: 57 58 /// Create a PTHLexer for the specified token stream. 59 PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D, 60 const char* ppcond, PTHManager& PM); 61 62 ~PTHLexer() {} 63 64 /// Lex - Return the next token. 65 void Lex(Token &Tok); 66 67 void getEOF(Token &Tok); 68 69 /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an 70 /// uninterpreted string. This switches the lexer out of directive mode. 71 void DiscardToEndOfLine(); 72 73 /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a 74 /// tok::l_paren token, 0 if it is something else and 2 if there are no more 75 /// tokens controlled by this lexer. 76 unsigned isNextPPTokenLParen() { 77 // isNextPPTokenLParen is not on the hot path, and all we care about is 78 // whether or not we are at a token with kind tok::eof or tok::l_paren. 79 // Just read the first byte from the current token pointer to determine 80 // its kind. 81 tok::TokenKind x = (tok::TokenKind) (unsigned char) *CurPtr; 82 return x == tok::eof ? 2 : x == tok::l_paren; 83 } 84 85 /// IndirectLex - An indirect call to 'Lex' that can be invoked via 86 /// the PreprocessorLexer interface. 87 void IndirectLex(Token &Result) { Lex(Result); } 88 89 /// getSourceLocation - Return a source location for the token in 90 /// the current file. 91 SourceLocation getSourceLocation(); 92 93 /// SkipBlock - Used by Preprocessor to skip the current conditional block. 94 bool SkipBlock(); 95}; 96 97} // end namespace clang 98 99#endif 100