PTHLexer.h revision 59d08cb672136322375e5400578ee1fbd0947de2
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"
1882a500b141b9a8001dac69f047478a43e2aebdffTed Kremenek#include <vector>
19274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
20274b20863a728cc6a31ee75c670e3733600c1531Ted Kremeneknamespace clang {
21274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
220c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenekclass PTHManager;
230c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek
24274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenekclass PTHLexer : public PreprocessorLexer {
250c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek  /// TokBuf - Buffer from PTH file containing raw token data.
260c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek  const char* TokBuf;
27cd223444d1680290efe11da657faafc9a1ac14baTed Kremenek
28cd223444d1680290efe11da657faafc9a1ac14baTed Kremenek  /// CurPtr - Pointer into current offset of the token buffer where
29cd223444d1680290efe11da657faafc9a1ac14baTed Kremenek  ///  the next token will be read.
30cd223444d1680290efe11da657faafc9a1ac14baTed Kremenek  const char* CurPtr;
31cd223444d1680290efe11da657faafc9a1ac14baTed Kremenek
32cd223444d1680290efe11da657faafc9a1ac14baTed Kremenek  /// LastHashTokPtr - Pointer into TokBuf of the last processed '#'
33cd223444d1680290efe11da657faafc9a1ac14baTed Kremenek  ///  token that appears at the start of a line.
34cd223444d1680290efe11da657faafc9a1ac14baTed Kremenek  const char* LastHashTokPtr;
35268ee7016a2811803989487c0ad3799486092c63Ted Kremenek
36268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  /// PPCond - Pointer to a side table in the PTH file that provides a
37268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  ///  a consise summary of the preproccessor conditional block structure.
38268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  ///  This is used to perform quick skipping of conditional blocks.
39268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  const char* PPCond;
40268ee7016a2811803989487c0ad3799486092c63Ted Kremenek
41268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  /// CurPPCondPtr - Pointer inside PPCond that refers to the next entry
42268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  ///  to process when doing quick skipping of preprocessor blocks.
43268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  const char* CurPPCondPtr;
4482a500b141b9a8001dac69f047478a43e2aebdffTed Kremenek
45274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  PTHLexer(const PTHLexer&);  // DO NOT IMPLEMENT
46274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  void operator=(const PTHLexer&); // DO NOT IMPLEMENT
470c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek
480c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek  /// ReadToken - Used by PTHLexer to read tokens TokBuf.
490c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek  void ReadToken(Token& T);
50274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
510c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek  /// PTHMgr - The PTHManager object that created this PTHLexer.
520c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek  PTHManager& PTHMgr;
530c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek
540c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek  Token EofToken;
550c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek
5682a500b141b9a8001dac69f047478a43e2aebdffTed Kremenekpublic:
57274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
58274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  /// Create a PTHLexer for the specified token stream.
590c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek  PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D,
60268ee7016a2811803989487c0ad3799486092c63Ted Kremenek           const char* ppcond, PTHManager& PM);
610c6a77bc1f52f282a969538f139ebde429076ed3Ted Kremenek
62274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  ~PTHLexer() {}
63274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
64274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  /// Lex - Return the next token.
65274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek  void Lex(Token &Tok);
66274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
6759d08cb672136322375e5400578ee1fbd0947de2Ted Kremenek  void getEOF(Token &Tok);
68274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
699f1384f7db76e24068f6c9d7d881714addb6c029Ted Kremenek  /// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
7017ff58a63197b398ae52697b088dc0fb8b255519Ted Kremenek  /// uninterpreted string.  This switches the lexer out of directive mode.
7117ff58a63197b398ae52697b088dc0fb8b255519Ted Kremenek  void DiscardToEndOfLine();
722f1c0243f7fc5d12446efcb006c071854c345923Ted Kremenek
732f1c0243f7fc5d12446efcb006c071854c345923Ted Kremenek  /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
742f1c0243f7fc5d12446efcb006c071854c345923Ted Kremenek  /// tok::l_paren token, 0 if it is something else and 2 if there are no more
752f1c0243f7fc5d12446efcb006c071854c345923Ted Kremenek  /// tokens controlled by this lexer.
7631aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek  unsigned isNextPPTokenLParen() {
77daeee815169f37f2a49f80af7bd104722672ad97Ted Kremenek    // isNextPPTokenLParen is not on the hot path, and all we care about is
78daeee815169f37f2a49f80af7bd104722672ad97Ted Kremenek    // whether or not we are at a token with kind tok::eof or tok::l_paren.
79daeee815169f37f2a49f80af7bd104722672ad97Ted Kremenek    // Just read the first byte from the current token pointer to determine
80daeee815169f37f2a49f80af7bd104722672ad97Ted Kremenek    // its kind.
81e36dabb2d9567c98734a1063ac7748dc37a999ceChris Lattner    tok::TokenKind x = (tok::TokenKind) (unsigned char) *CurPtr;
82daeee815169f37f2a49f80af7bd104722672ad97Ted Kremenek    return x == tok::eof ? 2 : x == tok::l_paren;
83daeee815169f37f2a49f80af7bd104722672ad97Ted Kremenek  }
8431aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek
85ac2dda65d2d39c0a83d95bdf6237edbf4685bc58Ted Kremenek  /// IndirectLex - An indirect call to 'Lex' that can be invoked via
86ac2dda65d2d39c0a83d95bdf6237edbf4685bc58Ted Kremenek  ///  the PreprocessorLexer interface.
87ac2dda65d2d39c0a83d95bdf6237edbf4685bc58Ted Kremenek  void IndirectLex(Token &Result) { Lex(Result); }
8831aba425a01c8c957e662ccfaa71f923d0f0932aTed Kremenek
89bc0f6bc0391ecdff331885cdc769c20b2cb628a6Ted Kremenek  /// getSourceLocation - Return a source location for the token in
90bc0f6bc0391ecdff331885cdc769c20b2cb628a6Ted Kremenek  /// the current file.
9130a12ec2a7f331d9e08acabe7cda853aaa7ba54bTed Kremenek  SourceLocation getSourceLocation();
9230a12ec2a7f331d9e08acabe7cda853aaa7ba54bTed Kremenek
93268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  /// SkipBlock - Used by Preprocessor to skip the current conditional block.
94268ee7016a2811803989487c0ad3799486092c63Ted Kremenek  bool SkipBlock();
95274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek};
96274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
97274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek}  // end namespace clang
98274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek
99274b20863a728cc6a31ee75c670e3733600c1531Ted Kremenek#endif
100