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 #include "clang/Basic/TokenKinds.h"
20 #include "clang/Lex/Token.h"
21 
22 namespace clang {
23 
24 class Preprocessor;
25 class PTHManager;
26 
27 class PTHLexer : public PreprocessorLexer {
28  SourceLocation FileStartLoc;
29 
30  /// TokBuf - Buffer from PTH file containing raw token data.
31  const unsigned char* TokBuf;
32 
33  /// CurPtr - Pointer into current offset of the token buffer where
34  /// the next token will be read.
35  const unsigned char* CurPtr;
36 
37  /// LastHashTokPtr - Pointer into TokBuf of the last processed '#'
38  /// token that appears at the start of a line.
39  const unsigned char* LastHashTokPtr = nullptr;
40 
41  /// PPCond - Pointer to a side table in the PTH file that provides a
42  /// a concise summary of the preprocessor conditional block structure.
43  /// This is used to perform quick skipping of conditional blocks.
44  const unsigned char* PPCond;
45 
46  /// CurPPCondPtr - Pointer inside PPCond that refers to the next entry
47  /// to process when doing quick skipping of preprocessor blocks.
48  const unsigned char* CurPPCondPtr;
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 
67 public:
68  PTHLexer(const PTHLexer &) = delete;
69  PTHLexer &operator=(const PTHLexer &) = delete;
70  ~PTHLexer() override = default;
71 
72  /// Lex - Return the next token.
73  bool Lex(Token &Tok);
74 
75  void getEOF(Token &Tok);
76 
77  /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
78  /// uninterpreted string. This switches the lexer out of directive mode.
79  void DiscardToEndOfLine();
80 
81  /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
82  /// tok::l_paren token, 0 if it is something else and 2 if there are no more
83  /// tokens controlled by this lexer.
84  unsigned isNextPPTokenLParen() {
85  // isNextPPTokenLParen is not on the hot path, and all we care about is
86  // whether or not we are at a token with kind tok::eof or tok::l_paren.
87  // Just read the first byte from the current token pointer to determine
88  // its kind.
89  tok::TokenKind x = (tok::TokenKind)*CurPtr;
90  return x == tok::eof ? 2 : x == tok::l_paren;
91  }
92 
93  /// IndirectLex - An indirect call to 'Lex' that can be invoked via
94  /// the PreprocessorLexer interface.
95  void IndirectLex(Token &Result) override { Lex(Result); }
96 
97  /// getSourceLocation - Return a source location for the token in
98  /// the current file.
100 
101  /// SkipBlock - Used by Preprocessor to skip the current conditional block.
102  bool SkipBlock();
103 };
104 
105 } // namespace clang
106 
107 #endif // LLVM_CLANG_LEX_PTHLEXER_H
bool Lex(Token &Tok)
Lex - Return the next token.
Definition: PTHLexer.cpp:56
PTHLexer(Preprocessor &pp, FileID FID, const unsigned char *D, const unsigned char *ppcond, PTHManager &PM)
Create a PTHLexer for the specified token stream.
Definition: PTHLexer.cpp:49
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
PTHLexer & operator=(const PTHLexer &)=delete
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:170
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:298
Encodes a location in the source.
~PTHLexer() override=default
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
void getEOF(Token &Tok)
Definition: PTHLexer.cpp:165
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:199
Dataflow Directional Tag Classes.
unsigned isNextPPTokenLParen()
isNextPPTokenLParen - Return 1 if the next unexpanded token will return a tok::l_paren token...
Definition: PTHLexer.h:84
Defines the clang::TokenKind enum and support functions.
Defines the clang::SourceLocation class and associated facilities.
void IndirectLex(Token &Result) override
IndirectLex - An indirect call to 'Lex' that can be invoked via the PreprocessorLexer interface...
Definition: PTHLexer.h:95
Defines the PreprocessorLexer interface.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:127