blob: 8c7c7ee19eedfb0abef0f8504d42574416183aab [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();
Jamie Madillacf2f3a2017-11-21 19:22:44 -050021 ~Input();
Zhenyao Mod526f982014-05-13 14:51:19 -070022 Input(size_t count, const char *const string[], const int length[]);
alokp@chromium.org98eec912012-05-01 10:04:08 +000023
Jamie Madillf832c9d2016-12-12 17:38:48 -050024 size_t count() const { return mCount; }
25 const char *string(size_t index) const { return mString[index]; }
26 size_t length(size_t index) const { return mLength[index]; }
alokp@chromium.org98eec912012-05-01 10:04:08 +000027
Olli Etuaho26e355b2015-08-14 14:16:19 +030028 size_t read(char *buf, size_t maxSize, int *lineNo);
alokp@chromium.org98eec912012-05-01 10:04:08 +000029
30 struct Location
31 {
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000032 size_t sIndex; // String index;
33 size_t cIndex; // Char index.
alokp@chromium.org98eec912012-05-01 10:04:08 +000034
Jamie Madillf832c9d2016-12-12 17:38:48 -050035 Location() : sIndex(0), cIndex(0) {}
alokp@chromium.org98eec912012-05-01 10:04:08 +000036 };
Zhenyao Mod526f982014-05-13 14:51:19 -070037 const Location &readLoc() const { return mReadLoc; }
alokp@chromium.org98eec912012-05-01 10:04:08 +000038
39 private:
Olli Etuaho26e355b2015-08-14 14:16:19 +030040 // Skip a character and return the next character after the one that was skipped.
41 // Return nullptr if data runs out.
42 const char *skipChar();
43
alokp@chromium.org98eec912012-05-01 10:04:08 +000044 // Input.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000045 size_t mCount;
Jamie Madillf832c9d2016-12-12 17:38:48 -050046 const char *const *mString;
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000047 std::vector<size_t> mLength;
alokp@chromium.org98eec912012-05-01 10:04:08 +000048
49 Location mReadLoc;
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000050};
51
52} // namespace pp
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000053
Geoff Lang0a73dd82014-11-19 16:18:08 -050054#endif // COMPILER_PREPROCESSOR_INPUT_H_