File indexing completed on 2026-05-10 08:44:32
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_SUPPORT_LINEITERATOR_H
0010 #define LLVM_SUPPORT_LINEITERATOR_H
0011
0012 #include "llvm/ADT/StringRef.h"
0013 #include "llvm/Support/DataTypes.h"
0014 #include "llvm/Support/MemoryBufferRef.h"
0015 #include <iterator>
0016 #include <optional>
0017
0018 namespace llvm {
0019
0020 class MemoryBuffer;
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 class line_iterator {
0034 std::optional<MemoryBufferRef> Buffer;
0035 char CommentMarker = '\0';
0036 bool SkipBlanks = true;
0037
0038 unsigned LineNumber = 1;
0039 StringRef CurrentLine;
0040
0041 public:
0042 using iterator_category = std::forward_iterator_tag;
0043 using value_type = StringRef;
0044 using difference_type = std::ptrdiff_t;
0045 using pointer = value_type *;
0046 using reference = value_type &;
0047
0048
0049 line_iterator() = default;
0050
0051
0052 explicit line_iterator(const MemoryBufferRef &Buffer, bool SkipBlanks = true,
0053 char CommentMarker = '\0');
0054
0055
0056 explicit line_iterator(const MemoryBuffer &Buffer, bool SkipBlanks = true,
0057 char CommentMarker = '\0');
0058
0059
0060 bool is_at_eof() const { return !Buffer; }
0061
0062
0063 bool is_at_end() const { return is_at_eof(); }
0064
0065
0066 int64_t line_number() const { return LineNumber; }
0067
0068
0069 line_iterator &operator++() {
0070 advance();
0071 return *this;
0072 }
0073 line_iterator operator++(int) {
0074 line_iterator tmp(*this);
0075 advance();
0076 return tmp;
0077 }
0078
0079
0080 StringRef operator*() const { return CurrentLine; }
0081 const StringRef *operator->() const { return &CurrentLine; }
0082
0083 friend bool operator==(const line_iterator &LHS, const line_iterator &RHS) {
0084 return LHS.Buffer == RHS.Buffer &&
0085 LHS.CurrentLine.begin() == RHS.CurrentLine.begin();
0086 }
0087
0088 friend bool operator!=(const line_iterator &LHS, const line_iterator &RHS) {
0089 return !(LHS == RHS);
0090 }
0091
0092 private:
0093
0094 void advance();
0095 };
0096 }
0097
0098 #endif