blob: e2150f899e4ff3d2409e94c0a69906a928263bc2 [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
Geoff Lang197d5292018-04-25 14:29:00 -040013namespace angle
14{
15
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000016namespace pp
17{
18
alokp@chromium.org98eec912012-05-01 10:04:08 +000019// Holds and reads input for Lexer.
20class Input
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000021{
alokp@chromium.org98eec912012-05-01 10:04:08 +000022 public:
alokp@chromium.org28182482012-04-24 23:07:34 +000023 Input();
Jamie Madillacf2f3a2017-11-21 19:22:44 -050024 ~Input();
Zhenyao Mod526f982014-05-13 14:51:19 -070025 Input(size_t count, const char *const string[], const int length[]);
alokp@chromium.org98eec912012-05-01 10:04:08 +000026
Jamie Madillf832c9d2016-12-12 17:38:48 -050027 size_t count() const { return mCount; }
28 const char *string(size_t index) const { return mString[index]; }
29 size_t length(size_t index) const { return mLength[index]; }
alokp@chromium.org98eec912012-05-01 10:04:08 +000030
Olli Etuaho26e355b2015-08-14 14:16:19 +030031 size_t read(char *buf, size_t maxSize, int *lineNo);
alokp@chromium.org98eec912012-05-01 10:04:08 +000032
33 struct Location
34 {
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000035 size_t sIndex; // String index;
36 size_t cIndex; // Char index.
alokp@chromium.org98eec912012-05-01 10:04:08 +000037
Jamie Madillf832c9d2016-12-12 17:38:48 -050038 Location() : sIndex(0), cIndex(0) {}
alokp@chromium.org98eec912012-05-01 10:04:08 +000039 };
Zhenyao Mod526f982014-05-13 14:51:19 -070040 const Location &readLoc() const { return mReadLoc; }
alokp@chromium.org98eec912012-05-01 10:04:08 +000041
42 private:
Olli Etuaho26e355b2015-08-14 14:16:19 +030043 // Skip a character and return the next character after the one that was skipped.
44 // Return nullptr if data runs out.
45 const char *skipChar();
46
alokp@chromium.org98eec912012-05-01 10:04:08 +000047 // Input.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000048 size_t mCount;
Jamie Madillf832c9d2016-12-12 17:38:48 -050049 const char *const *mString;
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000050 std::vector<size_t> mLength;
alokp@chromium.org98eec912012-05-01 10:04:08 +000051
52 Location mReadLoc;
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000053};
54
55} // namespace pp
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000056
Geoff Lang197d5292018-04-25 14:29:00 -040057} // namespace angle
58
Geoff Lang0a73dd82014-11-19 16:18:08 -050059#endif // COMPILER_PREPROCESSOR_INPUT_H_