• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef COMPILER_PREPROCESSOR_INPUT_H_
16 #define COMPILER_PREPROCESSOR_INPUT_H_
17 
18 #include <cstddef>
19 #include <vector>
20 #include <climits>
21 
22 namespace pp
23 {
24 
25 // Holds and reads input for Lexer.
26 class Input
27 {
28 public:
29 	Input();
30 	~Input();
31 	Input(size_t count, const char *const string[], const int length[]);
32 
count()33 	size_t count() const { return mCount; }
string(size_t index)34 	const char *string(size_t index) const { return mString[index]; }
length(size_t index)35 	size_t length(size_t index) const { return mLength[index]; }
36 
37 	size_t read(char *buf, size_t maxSize, int *lineNo);
38 
39 	struct Location
40 	{
41 		size_t sIndex;  // String index;
42 		size_t cIndex;  // Char index.
43 
LocationLocation44 		Location() : sIndex(0), cIndex(0) {}
45 	};
readLoc()46 	const Location &readLoc() const { return mReadLoc; }
47 
48 private:
49 	// Skip a character and return the next character after the one that was skipped.
50 	// Return nullptr if data runs out.
51 	const char *skipChar();
52 
53 	// Input.
54 	size_t mCount;
55 	const char *const *mString;
56 	std::vector<size_t> mLength;
57 
58 	Location mReadLoc;
59 };
60 
61 }  // namespace pp
62 #endif  // COMPILER_PREPROCESSOR_INPUT_H_
63 
64