blob: d5f385832be1444f2bb60b4bbfcdb07a4155ec87 [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
Jamie Madillf832c9d2016-12-12 17:38:48 -050023 size_t count() const { return mCount; }
24 const char *string(size_t index) const { return mString[index]; }
25 size_t length(size_t index) const { return mLength[index]; }
alokp@chromium.org98eec912012-05-01 10:04:08 +000026
Olli Etuaho26e355b2015-08-14 14:16:19 +030027 size_t read(char *buf, size_t maxSize, int *lineNo);
alokp@chromium.org98eec912012-05-01 10:04:08 +000028
29 struct Location
30 {
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000031 size_t sIndex; // String index;
32 size_t cIndex; // Char index.
alokp@chromium.org98eec912012-05-01 10:04:08 +000033
Jamie Madillf832c9d2016-12-12 17:38:48 -050034 Location() : sIndex(0), cIndex(0) {}
alokp@chromium.org98eec912012-05-01 10:04:08 +000035 };
Zhenyao Mod526f982014-05-13 14:51:19 -070036 const Location &readLoc() const { return mReadLoc; }
alokp@chromium.org98eec912012-05-01 10:04:08 +000037
38 private:
Olli Etuaho26e355b2015-08-14 14:16:19 +030039 // Skip a character and return the next character after the one that was skipped.
40 // Return nullptr if data runs out.
41 const char *skipChar();
42
alokp@chromium.org98eec912012-05-01 10:04:08 +000043 // Input.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000044 size_t mCount;
Jamie Madillf832c9d2016-12-12 17:38:48 -050045 const char *const *mString;
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000046 std::vector<size_t> mLength;
alokp@chromium.org98eec912012-05-01 10:04:08 +000047
48 Location mReadLoc;
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000049};
50
51} // namespace pp
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000052
Geoff Lang0a73dd82014-11-19 16:18:08 -050053#endif // COMPILER_PREPROCESSOR_INPUT_H_