PTHLexer.h revision 7415326dcbba6f333f5f7708ac1bf4982f3adb5a
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  PTHLexer(const PTHLexer&);  // DO NOT IMPLEMENT
29  void operator=(const PTHLexer&); // DO NOT IMPLEMENT
30
31  /// ReadToken - Used by PTHLexer to read tokens TokBuf.
32  void ReadToken(Token& T);
33
34  /// PTHMgr - The PTHManager object that created this PTHLexer.
35  PTHManager& PTHMgr;
36
37  Token LastFetched;
38  Token EofToken;
39  bool NeedsFetching;
40
41public:
42
43  /// Create a PTHLexer for the specified token stream.
44  PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D,
45           PTHManager& PM);
46
47  ~PTHLexer() {}
48
49  /// Lex - Return the next token.
50  void Lex(Token &Tok);
51
52  void setEOF(Token &Tok);
53
54  /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
55  /// uninterpreted string.  This switches the lexer out of directive mode.
56  void DiscardToEndOfLine();
57
58  /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
59  /// tok::l_paren token, 0 if it is something else and 2 if there are no more
60  /// tokens controlled by this lexer.
61  unsigned isNextPPTokenLParen() {
62    return AtLastToken() ? 2 : GetToken().is(tok::l_paren);
63  }
64
65  /// IndirectLex - An indirect call to 'Lex' that can be invoked via
66  ///  the PreprocessorLexer interface.
67  void IndirectLex(Token &Result) { Lex(Result); }
68
69  /// getSourceLocation - Return a source location for the token in
70  /// the current file.
71  SourceLocation getSourceLocation() { return GetToken().getLocation(); }
72
73private:
74
75  /// AtLastToken - Returns true if the PTHLexer is at the last token.
76  bool AtLastToken() {
77    Token T = GetToken();
78    return T.is(tok::eof) ? EofToken = T, true : false;
79  }
80
81  /// GetToken - Returns the next token.  This method does not advance the
82  ///  PTHLexer to the next token.
83  Token GetToken();
84
85  /// AdvanceToken - Advances the PTHLexer to the next token.
86  void AdvanceToken() { NeedsFetching = true; }
87
88  bool LexEndOfFile(Token &Result);
89};
90
91}  // end namespace clang
92
93#endif
94