1193326Sed//===--- PTHLexer.h - Lexer based on Pre-tokenized input --------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the PTHLexer interface. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_PTHLEXER_H 15193326Sed#define LLVM_CLANG_PTHLEXER_H 16193326Sed 17193326Sed#include "clang/Lex/PreprocessorLexer.h" 18193326Sed 19193326Sednamespace clang { 20198092Srdivacky 21193326Sedclass PTHManager; 22193326Sedclass PTHSpellingSearch; 23198092Srdivacky 24193326Sedclass PTHLexer : public PreprocessorLexer { 25193326Sed SourceLocation FileStartLoc; 26198092Srdivacky 27193326Sed /// TokBuf - Buffer from PTH file containing raw token data. 28193326Sed const unsigned char* TokBuf; 29198092Srdivacky 30193326Sed /// CurPtr - Pointer into current offset of the token buffer where 31193326Sed /// the next token will be read. 32193326Sed const unsigned char* CurPtr; 33198092Srdivacky 34193326Sed /// LastHashTokPtr - Pointer into TokBuf of the last processed '#' 35193326Sed /// token that appears at the start of a line. 36193326Sed const unsigned char* LastHashTokPtr; 37198092Srdivacky 38193326Sed /// PPCond - Pointer to a side table in the PTH file that provides a 39193326Sed /// a consise summary of the preproccessor conditional block structure. 40193326Sed /// This is used to perform quick skipping of conditional blocks. 41193326Sed const unsigned char* PPCond; 42198092Srdivacky 43193326Sed /// CurPPCondPtr - Pointer inside PPCond that refers to the next entry 44193326Sed /// to process when doing quick skipping of preprocessor blocks. 45193326Sed const unsigned char* CurPPCondPtr; 46193326Sed 47243830Sdim PTHLexer(const PTHLexer &) LLVM_DELETED_FUNCTION; 48243830Sdim void operator=(const PTHLexer &) LLVM_DELETED_FUNCTION; 49198092Srdivacky 50193326Sed /// ReadToken - Used by PTHLexer to read tokens TokBuf. 51193326Sed void ReadToken(Token& T); 52212904Sdim 53212904Sdim bool LexEndOfFile(Token &Result); 54193326Sed 55193326Sed /// PTHMgr - The PTHManager object that created this PTHLexer. 56193326Sed PTHManager& PTHMgr; 57198092Srdivacky 58193326Sed Token EofToken; 59193326Sed 60193326Sedprotected: 61193326Sed friend class PTHManager; 62193326Sed 63193326Sed /// Create a PTHLexer for the specified token stream. 64193326Sed PTHLexer(Preprocessor& pp, FileID FID, const unsigned char *D, 65193326Sed const unsigned char* ppcond, PTHManager &PM); 66198092Srdivackypublic: 67193326Sed 68193326Sed ~PTHLexer() {} 69198092Srdivacky 70193326Sed /// Lex - Return the next token. 71193326Sed void Lex(Token &Tok); 72198092Srdivacky 73193326Sed void getEOF(Token &Tok); 74198092Srdivacky 75193326Sed /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an 76193326Sed /// uninterpreted string. This switches the lexer out of directive mode. 77193326Sed void DiscardToEndOfLine(); 78198092Srdivacky 79193326Sed /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a 80193326Sed /// tok::l_paren token, 0 if it is something else and 2 if there are no more 81193326Sed /// tokens controlled by this lexer. 82193326Sed unsigned isNextPPTokenLParen() { 83193326Sed // isNextPPTokenLParen is not on the hot path, and all we care about is 84193326Sed // whether or not we are at a token with kind tok::eof or tok::l_paren. 85193326Sed // Just read the first byte from the current token pointer to determine 86193326Sed // its kind. 87193326Sed tok::TokenKind x = (tok::TokenKind)*CurPtr; 88193326Sed return x == tok::eof ? 2 : x == tok::l_paren; 89198092Srdivacky } 90193326Sed 91193326Sed /// IndirectLex - An indirect call to 'Lex' that can be invoked via 92193326Sed /// the PreprocessorLexer interface. 93193326Sed void IndirectLex(Token &Result) { Lex(Result); } 94198092Srdivacky 95193326Sed /// getSourceLocation - Return a source location for the token in 96193326Sed /// the current file. 97193326Sed SourceLocation getSourceLocation(); 98193326Sed 99193326Sed /// SkipBlock - Used by Preprocessor to skip the current conditional block. 100193326Sed bool SkipBlock(); 101193326Sed}; 102193326Sed 103193326Sed} // end namespace clang 104193326Sed 105193326Sed#endif 106