blob: ecbb04962dfe9c587ac728c1f38ddb42264f9e37 [file] [log] [blame]
alokp@chromium.org4e4b8072011-08-07 05:36:04 +00001//
2// Copyright (c) 2011 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_INPUT_H_
8#define COMPILER_PREPROCESSOR_INPUT_H_
9
Corentin Wallez054f7ed2016-09-20 17:15:59 -040010#include <cstddef>
alokp@chromium.org30a487c2012-05-02 17:30:46 +000011#include <vector>
alokp@chromium.org98eec912012-05-01 10:04:08 +000012
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000013namespace pp
14{
15
alokp@chromium.org98eec912012-05-01 10:04:08 +000016// Holds and reads input for Lexer.
17class Input
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000018{
alokp@chromium.org98eec912012-05-01 10:04:08 +000019 public:
alokp@chromium.org28182482012-04-24 23:07:34 +000020 Input();
Zhenyao Mod526f982014-05-13 14:51:19 -070021 Input(size_t count, const char *const string[], const int length[]);
alokp@chromium.org98eec912012-05-01 10:04:08 +000022
Zhenyao Mod526f982014-05-13 14:51:19 -070023 size_t count() const
24 {
25 return mCount;
26 }
27 const char *string(size_t index) const
28 {
29 return mString[index];
30 }
31 size_t length(size_t index) const
32 {
33 return mLength[index];
34 }
alokp@chromium.org98eec912012-05-01 10:04:08 +000035
Olli Etuaho26e355b2015-08-14 14:16:19 +030036 size_t read(char *buf, size_t maxSize, int *lineNo);
alokp@chromium.org98eec912012-05-01 10:04:08 +000037
38 struct Location
39 {
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000040 size_t sIndex; // String index;
41 size_t cIndex; // Char index.
alokp@chromium.org98eec912012-05-01 10:04:08 +000042
Zhenyao Mod526f982014-05-13 14:51:19 -070043 Location()
44 : sIndex(0),
45 cIndex(0)
46 {
47 }
alokp@chromium.org98eec912012-05-01 10:04:08 +000048 };
Zhenyao Mod526f982014-05-13 14:51:19 -070049 const Location &readLoc() const { return mReadLoc; }
alokp@chromium.org98eec912012-05-01 10:04:08 +000050
51 private:
Olli Etuaho26e355b2015-08-14 14:16:19 +030052 // Skip a character and return the next character after the one that was skipped.
53 // Return nullptr if data runs out.
54 const char *skipChar();
55
alokp@chromium.org98eec912012-05-01 10:04:08 +000056 // Input.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000057 size_t mCount;
Zhenyao Mod526f982014-05-13 14:51:19 -070058 const char * const *mString;
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000059 std::vector<size_t> mLength;
alokp@chromium.org98eec912012-05-01 10:04:08 +000060
61 Location mReadLoc;
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000062};
63
64} // namespace pp
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000065
Geoff Lang0a73dd82014-11-19 16:18:08 -050066#endif // COMPILER_PREPROCESSOR_INPUT_H_