blob: c603135fc77dc5bc3222356e3224d0bf019b5e29 [file] [log] [blame]
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001//
2// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#ifndef COMPILER_PREPROCESSOR_TOKENIZER_H_
8#define COMPILER_PREPROCESSOR_TOKENIZER_H_
9
10#include "Input.h"
11#include "Lexer.h"
12#include "pp_utils.h"
13
14namespace pp
15{
16
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000017class Diagnostics;
18
alokp@chromium.org04d7d222012-05-16 19:24:07 +000019class Tokenizer : public Lexer
20{
21 public:
22 struct Context
23 {
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000024 Diagnostics* diagnostics;
25
alokp@chromium.org04d7d222012-05-16 19:24:07 +000026 Input input;
27 // The location where yytext points to. Token location should track
28 // scanLoc instead of Input::mReadLoc because they may not be the same
29 // if text is buffered up in the scanner input buffer.
30 Input::Location scanLoc;
31
32 bool leadingSpace;
33 bool lineStart;
34 };
daniel@transgaming.coma16a55f2012-12-20 20:51:54 +000035 static const std::size_t kMaxTokenLength;
alokp@chromium.org04d7d222012-05-16 19:24:07 +000036
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000037 Tokenizer(Diagnostics* diagnostics);
alokp@chromium.org04d7d222012-05-16 19:24:07 +000038 ~Tokenizer();
39
40 bool init(int count, const char* const string[], const int length[]);
alokp@chromium.org46aa13d2012-06-15 15:40:27 +000041
42 void setFileNumber(int file);
43 void setLineNumber(int line);
44
alokp@chromium.org04d7d222012-05-16 19:24:07 +000045 virtual void lex(Token* token);
46
47 private:
48 PP_DISALLOW_COPY_AND_ASSIGN(Tokenizer);
49 bool initScanner();
50 void destroyScanner();
51
52 void* mHandle; // Scanner handle.
53 Context mContext; // Scanner extra.
54};
55
56} // namespace pp
57#endif // COMPILER_PREPROCESSOR_TOKENIZER_H_
58