LLVM: lib/Support/LineIterator.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

11

12using namespace llvm;

13

15 if (*P == '\n')

16 return true;

17 if (*P == '\r' && *(P + 1) == '\n')

18 return true;

19 return false;

20}

21

23 if (*P == '\n') {

24 ++P;

25 return true;

26 }

27 if (*P == '\r' && *(P + 1) == '\n') {

28 P += 2;

29 return true;

30 }

31 return false;

32}

33

35 char CommentMarker)

36 : line_iterator(Buffer.getMemBufferRef(), SkipBlanks, CommentMarker) {}

37

39 char CommentMarker)

40 : Buffer(Buffer.getBufferSize() ? std::optional<MemoryBufferRef>(Buffer)

41 : std::nullopt),

42 CommentMarker(CommentMarker), SkipBlanks(SkipBlanks),

43 CurrentLine(Buffer.getBufferSize() ? Buffer.getBufferStart() : nullptr,

44 0) {

45

46

47 if (Buffer.getBufferSize()) {

48 assert(Buffer.getBufferEnd()[0] == '\0');

49

50 if (SkipBlanks || !isAtLineEnd(Buffer.getBufferStart()))

51 advance();

52 }

53}

54

55void line_iterator::advance() {

56 assert(Buffer && "Cannot advance past the end!");

57

58 const char *Pos = CurrentLine.end();

59 assert(Pos == Buffer->getBufferStart() || isAtLineEnd(Pos) || *Pos == '\0');

60

62 ++LineNumber;

64

65 } else if (CommentMarker == '\0') {

66

68 ++LineNumber;

69 } else {

70

71 for (;;) {

73 break;

74 if (*Pos == CommentMarker)

75 do {

76 ++Pos;

77 } while (*Pos != '\0' && isAtLineEnd(Pos));

79 break;

80 ++LineNumber;

81 }

82 }

83

84 if (*Pos == '\0') {

85

86 Buffer = std::nullopt;

87 CurrentLine = StringRef();

88 return;

89 }

90

91

95 }

96

97 CurrentLine = StringRef(Pos, Length);

98}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static bool skipIfAtLineEnd(const char *&P)

Definition LineIterator.cpp:22

static bool isAtLineEnd(const char *P)

Definition LineIterator.cpp:14

This interface provides simple read-only access to a block of memory, and provides simple methods for...

line_iterator()=default

Default construct an "end" iterator.

This is an optimization pass for GlobalISel generic memory operations.

Implement std::hash so that hash_code can be used in STL containers.