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 <vector> 19 20 namespace pp 21 { 22 23 // Holds and reads input for Lexer. 24 class Input 25 { 26 public: 27 Input(); 28 Input(int count, const char* const string[], const int length[]); 29 count()30 int count() const { return mCount; } string(int index)31 const char* string(int index) const { return mString[index]; } length(int index)32 int length(int index) const { return mLength[index]; } 33 34 int read(char* buf, int maxSize); 35 36 struct Location 37 { 38 int sIndex; // String index; 39 int cIndex; // Char index. 40 LocationLocation41 Location() : sIndex(0), cIndex(0) { } 42 }; readLoc()43 const Location& readLoc() const { return mReadLoc; } 44 45 private: 46 // Input. 47 int mCount; 48 const char* const* mString; 49 std::vector<int> mLength; 50 51 Location mReadLoc; 52 }; 53 54 } // namespace pp 55 #endif // COMPILER_PREPROCESSOR_INPUT_H_ 56 57