clang  6.0.0svn
PTHLexer.h
Go to the documentation of this file.
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_LEX_PTHLEXER_H
15 #define LLVM_CLANG_LEX_PTHLEXER_H
16 
18 
19 namespace clang {
20 
21 class PTHManager;
22 class PTHSpellingSearch;
23 
24 class PTHLexer : public PreprocessorLexer {
25  SourceLocation FileStartLoc;
26 
27  /// TokBuf - Buffer from PTH file containing raw token data.
28  const unsigned char* TokBuf;
29 
30  /// CurPtr - Pointer into current offset of the token buffer where
31  /// the next token will be read.
32  const unsigned char* CurPtr;
33 
34  /// LastHashTokPtr - Pointer into TokBuf of the last processed '#'
35  /// token that appears at the start of a line.
36  const unsigned char* LastHashTokPtr;
37 
38  /// PPCond - Pointer to a side table in the PTH file that provides a
39  /// a concise summary of the preprocessor conditional block structure.
40  /// This is used to perform quick skipping of conditional blocks.
41  const unsigned char* PPCond;
42 
43  /// CurPPCondPtr - Pointer inside PPCond that refers to the next entry
44  /// to process when doing quick skipping of preprocessor blocks.
45  const unsigned char* CurPPCondPtr;
46 
47  PTHLexer(const PTHLexer &) = delete;
48  void operator=(const PTHLexer &) = delete;
49 
50  /// ReadToken - Used by PTHLexer to read tokens TokBuf.
51  void ReadToken(Token& T);
52 
53  bool LexEndOfFile(Token &Result);
54 
55  /// PTHMgr - The PTHManager object that created this PTHLexer.
56  PTHManager& PTHMgr;
57 
58  Token EofToken;
59 
60 protected:
61  friend class PTHManager;
62 
63  /// Create a PTHLexer for the specified token stream.
64  PTHLexer(Preprocessor& pp, FileID FID, const unsigned char *D,
65  const unsigned char* ppcond, PTHManager &PM);
66 public:
67  ~PTHLexer() override {}
68 
69  /// Lex - Return the next token.
70  bool Lex(Token &Tok);
71 
72  void getEOF(Token &Tok);
73 
74  /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
75  /// uninterpreted string. This switches the lexer out of directive mode.
76  void DiscardToEndOfLine();
77 
78  /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
79  /// tok::l_paren token, 0 if it is something else and 2 if there are no more
80  /// tokens controlled by this lexer.
81  unsigned isNextPPTokenLParen() {
82  // isNextPPTokenLParen is not on the hot path, and all we care about is
83  // whether or not we are at a token with kind tok::eof or tok::l_paren.
84  // Just read the first byte from the current token pointer to determine
85  // its kind.
86  tok::TokenKind x = (tok::TokenKind)*CurPtr;
87  return x == tok::eof ? 2 : x == tok::l_paren;
88  }
89 
90  /// IndirectLex - An indirect call to 'Lex' that can be invoked via
91  /// the PreprocessorLexer interface.
92  void IndirectLex(Token &Result) override { Lex(Result); }
93 
94  /// getSourceLocation - Return a source location for the token in
95  /// the current file.
97 
98  /// SkipBlock - Used by Preprocessor to skip the current conditional block.
99  bool SkipBlock();
100 };
101 
102 } // end namespace clang
103 
104 #endif
bool Lex(Token &Tok)
Lex - Return the next token.
Definition: PTHLexer.cpp:44
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
const FormatToken & Tok
const FileID FID
The SourceManager FileID corresponding to the file being lexed.
const FunctionProtoType * T
void DiscardToEndOfLine()
DiscardToEndOfLine - Read the rest of the current preprocessor line as an uninterpreted string...
Definition: PTHLexer.cpp:158
The result type of a method or function.
SourceLocation getSourceLocation() override
getSourceLocation - Return a source location for the token in the current file.
Definition: PTHLexer.cpp:285
Encodes a location in the source.
~PTHLexer() override
Definition: PTHLexer.h:67
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
void getEOF(Token &Tok)
Definition: PTHLexer.cpp:153
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool SkipBlock()
SkipBlock - Used by Preprocessor to skip the current conditional block.
Definition: PTHLexer.cpp:187
Dataflow Directional Tag Classes.
unsigned isNextPPTokenLParen()
isNextPPTokenLParen - Return 1 if the next unexpanded token will return a tok::l_paren token...
Definition: PTHLexer.h:81
void IndirectLex(Token &Result) override
IndirectLex - An indirect call to 'Lex' that can be invoked via the PreprocessorLexer interface...
Definition: PTHLexer.h:92
Defines the PreprocessorLexer interface.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:98