PTHLexer.h revision 31aba425a01c8c957e662ccfaa71f923d0f0932a
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
19namespace clang {
20
21class PTHLexer : public PreprocessorLexer {
22  /// Tokens - This is the pointer to an array of tokens that the macro is
23  /// defined to, with arguments expanded for function-like macros.  If this is
24  /// a token stream, these are the tokens we are returning.
25  const Token *Tokens;
26
27  /// LastTokenIdx - The index of the last token in Tokens.  This token
28  ///  will be an eof token.
29  unsigned LastTokenIdx;
30
31  /// CurTokenIdx - This is the index of the next token that Lex will return.
32  unsigned CurTokenIdx;
33
34  PTHLexer(const PTHLexer&);  // DO NOT IMPLEMENT
35  void operator=(const PTHLexer&); // DO NOT IMPLEMENT
36
37public:
38
39  /// Create a PTHLexer for the specified token stream.
40  PTHLexer(Preprocessor& pp, SourceLocation fileloc,
41           const Token *TokArray, unsigned NumToks);
42  ~PTHLexer() {}
43
44  /// Lex - Return the next token.
45  void Lex(Token &Tok);
46
47  void setEOF(Token &Tok);
48
49  /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
50  /// uninterpreted string.  This switches the lexer out of directive mode.
51  void DiscardToEndOfLine();
52
53  /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
54  /// tok::l_paren token, 0 if it is something else and 2 if there are no more
55  /// tokens controlled by this lexer.
56  unsigned isNextPPTokenLParen() {
57    return AtLastToken() ? 2 : GetToken().is(tok::l_paren);
58  }
59
60  /// IndirectLex - An indirect call to 'Lex' that can be invoked via
61  ///  the PreprocessorLexer interface.
62  void IndirectLex(Token &Result) { Lex(Result); }
63
64private:
65
66  /// AtLastToken - Returns true if the PTHLexer is at the last token.
67  bool AtLastToken() const { return CurTokenIdx == LastTokenIdx; }
68
69  /// GetToken - Returns the next token.  This method does not advance the
70  ///  PTHLexer to the next token.
71  Token GetToken() { return Tokens[CurTokenIdx]; }
72
73  /// AdvanceToken - Advances the PTHLexer to the next token.
74  void AdvanceToken() { ++CurTokenIdx; }
75};
76
77}  // end namespace clang
78
79#endif
80