PTHLexer.h revision b70e3dafb9618f34017061400dc19ac5e3539a6d
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 /// Returns the cached spelling of a token. 90 /// \param[in] sloc The SourceLocation of the token. 91 /// \param[out] Buffer If a token's spelling is found in the PTH file then 92 /// upon exit from this method \c Buffer will be set to the address of 93 /// the character array representing that spelling. No characters 94 /// are copied. 95 /// \returns The number of characters for the spelling of the token. This 96 /// value is 0 if the spelling could not be found in the PTH file. 97 unsigned getSpelling(SourceLocation sloc, const char *&Buffer); 98 99 /// getSourceLocation - Return a source location for the token in 100 /// the current file. 101 SourceLocation getSourceLocation(); 102 103 /// SkipBlock - Used by Preprocessor to skip the current conditional block. 104 bool SkipBlock(); 105}; 106 107} // end namespace clang 108 109#endif 110