blob: 6dfb19c66921e3360c58dc899b6afa5adea5f0be [file] [log] [blame]
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001//
Jamie Madill88f6e942014-02-19 10:27:53 -05002// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00003// 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
Corentin Wallez054f7ed2016-09-20 17:15:59 -040010#include "common/angleutils.h"
11#include "compiler/preprocessor/Input.h"
12#include "compiler/preprocessor/Lexer.h"
alokp@chromium.org04d7d222012-05-16 19:24:07 +000013
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 {
Zhenyao Mod526f982014-05-13 14:51:19 -070024 Diagnostics *diagnostics;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000025
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 };
35
Zhenyao Mod526f982014-05-13 14:51:19 -070036 Tokenizer(Diagnostics *diagnostics);
alokp@chromium.org04d7d222012-05-16 19:24:07 +000037 ~Tokenizer();
38
Zhenyao Mod526f982014-05-13 14:51:19 -070039 bool init(size_t count, const char * const string[], const int length[]);
alokp@chromium.org46aa13d2012-06-15 15:40:27 +000040
41 void setFileNumber(int file);
42 void setLineNumber(int line);
Jamie Madill5508f392014-02-20 13:31:36 -050043 void setMaxTokenSize(size_t maxTokenSize);
alokp@chromium.org46aa13d2012-06-15 15:40:27 +000044
Corentin Walleze5a1f272015-08-21 02:58:25 +020045 void lex(Token *token) override;
alokp@chromium.org04d7d222012-05-16 19:24:07 +000046
47 private:
alokp@chromium.org04d7d222012-05-16 19:24:07 +000048 bool initScanner();
49 void destroyScanner();
50
Zhenyao Mod526f982014-05-13 14:51:19 -070051 void *mHandle; // Scanner handle.
alokp@chromium.org04d7d222012-05-16 19:24:07 +000052 Context mContext; // Scanner extra.
Jamie Madill5508f392014-02-20 13:31:36 -050053 size_t mMaxTokenSize; // Maximum token size
alokp@chromium.org04d7d222012-05-16 19:24:07 +000054};
55
56} // namespace pp
alokp@chromium.org04d7d222012-05-16 19:24:07 +000057
Geoff Lang0a73dd82014-11-19 16:18:08 -050058#endif // COMPILER_PREPROCESSOR_TOKENIZER_H_