PTHLexer.h revision 31aba425a01c8c957e662ccfaa71f923d0f0932a
1274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//===--- PTHLexer.h - Lexer based on Pre-tokenized input --------*- C++ -*-===//
2274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//
3274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//                     The LLVM Compiler Infrastructure
4274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//
5274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek// This file is distributed under the University of Illinois Open Source
6274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek// License. See LICENSE.TXT for details.
7274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//
8274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//===----------------------------------------------------------------------===//
9274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//
10274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek// This file defines the PTHLexer interface.
11274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//
12274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek//===----------------------------------------------------------------------===//
13274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
14452e37837a48b2f0ced144784277fd4d28cbede9Ted Kremenek#ifndef LLVM_CLANG_PTHLEXER_H
15452e37837a48b2f0ced144784277fd4d28cbede9Ted Kremenek#define LLVM_CLANG_PTHLEXER_H
16274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
17274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek#include "clang/Lex/PreprocessorLexer.h"
18274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
19274b20863a728cc6a31ee75c670e3733600c1531Ted Kremeneknamespace clang {
20274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
21274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenekclass PTHLexer : public PreprocessorLexer {
22274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  /// Tokens - This is the pointer to an array of tokens that the macro is
23274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  /// defined to, with arguments expanded for function-like macros.  If this is
24274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  /// a token stream, these are the tokens we are returning.
25274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  const Token *Tokens;
26274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
27452e37837a48b2f0ced144784277fd4d28cbede9Ted Kremenek  /// LastTokenIdx - The index of the last token in Tokens.  This token
28452e37837a48b2f0ced144784277fd4d28cbede9Ted Kremenek  ///  will be an eof token.
2931aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  unsigned LastTokenIdx;
30274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
3131aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  /// CurTokenIdx - This is the index of the next token that Lex will return.
3231aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  unsigned CurTokenIdx;
33274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
34274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  PTHLexer(const PTHLexer&);  // DO NOT IMPLEMENT
35274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  void operator=(const PTHLexer&); // DO NOT IMPLEMENT
36274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
37274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenekpublic:
38274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
39274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  /// Create a PTHLexer for the specified token stream.
40274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  PTHLexer(Preprocessor& pp, SourceLocation fileloc,
41274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek           const Token *TokArray, unsigned NumToks);
42274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  ~PTHLexer() {}
43274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
44274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  /// Lex - Return the next token.
45274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  void Lex(Token &Tok);
46274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
47274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  void setEOF(Token &Tok);
48274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
499f1384f7db76e24068f6c9d7d881714addb6c029Ted Kremenek  /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
5017ff58a63197b398ae52697b088dc0fb8b255519Ted Kremenek  /// uninterpreted string.  This switches the lexer out of directive mode.
5117ff58a63197b398ae52697b088dc0fb8b255519Ted Kremenek  void DiscardToEndOfLine();
522f1c0243f7fc5d12446efcb006c071854c345923Ted Kremenek
532f1c0243f7fc5d12446efcb006c071854c345923Ted Kremenek  /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
542f1c0243f7fc5d12446efcb006c071854c345923Ted Kremenek  /// tok::l_paren token, 0 if it is something else and 2 if there are no more
552f1c0243f7fc5d12446efcb006c071854c345923Ted Kremenek  /// tokens controlled by this lexer.
5631aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  unsigned isNextPPTokenLParen() {
5731aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek    return AtLastToken() ? 2 : GetToken().is(tok::l_paren);
5831aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  }
5931aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek
60ac2dda65d2d39c0a83d95bdf6237edbf4685bc58Ted Kremenek  /// IndirectLex - An indirect call to 'Lex' that can be invoked via
61ac2dda65d2d39c0a83d95bdf6237edbf4685bc58Ted Kremenek  ///  the PreprocessorLexer interface.
62ac2dda65d2d39c0a83d95bdf6237edbf4685bc58Ted Kremenek  void IndirectLex(Token &Result) { Lex(Result); }
6331aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek
6431aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenekprivate:
6531aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek
6631aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  /// AtLastToken - Returns true if the PTHLexer is at the last token.
6731aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  bool AtLastToken() const { return CurTokenIdx == LastTokenIdx; }
6831aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek
6931aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  /// GetToken - Returns the next token.  This method does not advance the
7031aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  ///  PTHLexer to the next token.
7131aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  Token GetToken() { return Tokens[CurTokenIdx]; }
7231aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek
7331aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  /// AdvanceToken - Advances the PTHLexer to the next token.
7431aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  void AdvanceToken() { ++CurTokenIdx; }
75274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek};
76274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
77274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek}  // end namespace clang
78274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
79274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek#endif
80