clang API Documentation
00001 //===--- PTHLexer.h - Lexer based on Pre-tokenized input --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the PTHLexer interface. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_LEX_PTHLEXER_H 00015 #define LLVM_CLANG_LEX_PTHLEXER_H 00016 00017 #include "clang/Lex/PreprocessorLexer.h" 00018 00019 namespace clang { 00020 00021 class PTHManager; 00022 class PTHSpellingSearch; 00023 00024 class PTHLexer : public PreprocessorLexer { 00025 SourceLocation FileStartLoc; 00026 00027 /// TokBuf - Buffer from PTH file containing raw token data. 00028 const unsigned char* TokBuf; 00029 00030 /// CurPtr - Pointer into current offset of the token buffer where 00031 /// the next token will be read. 00032 const unsigned char* CurPtr; 00033 00034 /// LastHashTokPtr - Pointer into TokBuf of the last processed '#' 00035 /// token that appears at the start of a line. 00036 const unsigned char* LastHashTokPtr; 00037 00038 /// PPCond - Pointer to a side table in the PTH file that provides a 00039 /// a consise summary of the preproccessor conditional block structure. 00040 /// This is used to perform quick skipping of conditional blocks. 00041 const unsigned char* PPCond; 00042 00043 /// CurPPCondPtr - Pointer inside PPCond that refers to the next entry 00044 /// to process when doing quick skipping of preprocessor blocks. 00045 const unsigned char* CurPPCondPtr; 00046 00047 PTHLexer(const PTHLexer &) LLVM_DELETED_FUNCTION; 00048 void operator=(const PTHLexer &) LLVM_DELETED_FUNCTION; 00049 00050 /// ReadToken - Used by PTHLexer to read tokens TokBuf. 00051 void ReadToken(Token& T); 00052 00053 bool LexEndOfFile(Token &Result); 00054 00055 /// PTHMgr - The PTHManager object that created this PTHLexer. 00056 PTHManager& PTHMgr; 00057 00058 Token EofToken; 00059 00060 protected: 00061 friend class PTHManager; 00062 00063 /// Create a PTHLexer for the specified token stream. 00064 PTHLexer(Preprocessor& pp, FileID FID, const unsigned char *D, 00065 const unsigned char* ppcond, PTHManager &PM); 00066 public: 00067 00068 ~PTHLexer() {} 00069 00070 /// Lex - Return the next token. 00071 bool Lex(Token &Tok); 00072 00073 void getEOF(Token &Tok); 00074 00075 /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an 00076 /// uninterpreted string. This switches the lexer out of directive mode. 00077 void DiscardToEndOfLine(); 00078 00079 /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a 00080 /// tok::l_paren token, 0 if it is something else and 2 if there are no more 00081 /// tokens controlled by this lexer. 00082 unsigned isNextPPTokenLParen() { 00083 // isNextPPTokenLParen is not on the hot path, and all we care about is 00084 // whether or not we are at a token with kind tok::eof or tok::l_paren. 00085 // Just read the first byte from the current token pointer to determine 00086 // its kind. 00087 tok::TokenKind x = (tok::TokenKind)*CurPtr; 00088 return x == tok::eof ? 2 : x == tok::l_paren; 00089 } 00090 00091 /// IndirectLex - An indirect call to 'Lex' that can be invoked via 00092 /// the PreprocessorLexer interface. 00093 void IndirectLex(Token &Result) override { Lex(Result); } 00094 00095 /// getSourceLocation - Return a source location for the token in 00096 /// the current file. 00097 SourceLocation getSourceLocation() override; 00098 00099 /// SkipBlock - Used by Preprocessor to skip the current conditional block. 00100 bool SkipBlock(); 00101 }; 00102 00103 } // end namespace clang 00104 00105 #endif