aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Lex/PTHLexer.h
blob: f19d67958fa38e5ffd091e425f75be3c7709ce5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//===--- PTHLexer.h - Lexer based on Pre-tokenized input --------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the PTHLexer interface.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_PTHLEXER_H
#define LLVM_CLANG_PTHLEXER_H

#include "clang/Lex/PreprocessorLexer.h"
#include <vector>

namespace clang {
  
class PTHManager;
class PTHSpellingSearch;
  
class PTHLexer : public PreprocessorLexer {
private:
  /// FileID - The SourceManager FileID for the original source file.
  unsigned FileID;
  
  /// TokBuf - Buffer from PTH file containing raw token data.
  const char* TokBuf;
  
  /// CurPtr - Pointer into current offset of the token buffer where
  ///  the next token will be read.
  const char* CurPtr;
    
  /// LastHashTokPtr - Pointer into TokBuf of the last processed '#'
  ///  token that appears at the start of a line.
  const char* LastHashTokPtr;
  
  /// PPCond - Pointer to a side table in the PTH file that provides a
  ///  a consise summary of the preproccessor conditional block structure.
  ///  This is used to perform quick skipping of conditional blocks.
  const char* PPCond;
  
  /// CurPPCondPtr - Pointer inside PPCond that refers to the next entry
  ///  to process when doing quick skipping of preprocessor blocks.
  const char* CurPPCondPtr;

  /// MySpellingMgr - Reference to the spelling manager used to get spellings
  ///  for the source file indicated by \c FileID.
  PTHSpellingSearch& MySpellingSrch;  

  PTHLexer(const PTHLexer&);  // DO NOT IMPLEMENT
  void operator=(const PTHLexer&); // DO NOT IMPLEMENT
  
  /// ReadToken - Used by PTHLexer to read tokens TokBuf.
  void ReadToken(Token& T);

  /// PTHMgr - The PTHManager object that created this PTHLexer.
  PTHManager& PTHMgr;
  
  Token EofToken;

protected:
  friend class PTHManager;

  /// Create a PTHLexer for the specified token stream.
  PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D, 
           const char* ppcond,
           PTHSpellingSearch& mySpellingSrch,
           PTHManager& PM);
public:  

  ~PTHLexer() {}
    
  /// Lex - Return the next token.
  void Lex(Token &Tok);
  
  void getEOF(Token &Tok);
  
  /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
  /// uninterpreted string.  This switches the lexer out of directive mode.
  void DiscardToEndOfLine();
  
  /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
  /// tok::l_paren token, 0 if it is something else and 2 if there are no more
  /// tokens controlled by this lexer.
  unsigned isNextPPTokenLParen() {
    // isNextPPTokenLParen is not on the hot path, and all we care about is
    // whether or not we are at a token with kind tok::eof or tok::l_paren.
    // Just read the first byte from the current token pointer to determine
    // its kind.
    tok::TokenKind x = (tok::TokenKind) (unsigned char) *CurPtr;
    return x == tok::eof ? 2 : x == tok::l_paren;
  }    

  /// IndirectLex - An indirect call to 'Lex' that can be invoked via
  ///  the PreprocessorLexer interface.
  void IndirectLex(Token &Result) { Lex(Result); }

  /// Returns the cached spelling of a token.
  /// \param[in] sloc The SourceLocation of the token.
  /// \param[out] Buffer If a token's spelling is found in the PTH file then
  ///   upon exit from this method \c Buffer will be set to the address of
  ///   the character array representing that spelling.  No characters
  ///   are copied.
  /// \returns The number of characters for the spelling of the token.  This
  ///   value is 0 if the spelling could not be found in the PTH file.
  unsigned getSpelling(SourceLocation sloc, const char *&Buffer);
  
  /// getSourceLocation - Return a source location for the token in
  /// the current file.
  SourceLocation getSourceLocation();

  /// SkipBlock - Used by Preprocessor to skip the current conditional block.
  bool SkipBlock();
};

}  // end namespace clang

#endif