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

1

2

3

4

5

6

7

8

9

10

11

12

18#include

19

20using namespace llvm;

21

22

23

24

25

26void formatted_raw_ostream::UpdatePosition(const char *Ptr, size_t Size) {

27 unsigned &Column = Position.first;

28 unsigned &Line = Position.second;

29

30 auto ProcessUTF8CodePoint = [&Line, &Column](StringRef CP) {

33 Column += Width;

34

35

36 if (CP.size() > 1)

37 return;

38

39 switch (CP[0]) {

40 case '\n':

42 [[fallthrough]];

43 case '\r':

44 Column = 0;

45 break;

46 case '\t':

47

48 Column += (8 - (Column & 0x7)) & 0x7;

49 break;

50 }

51 };

52

53

54

55 if (PartialUTF8Char.size()) {

56 size_t BytesFromBuffer =

58 if (Size < BytesFromBuffer) {

59

60

61 PartialUTF8Char.append(StringRef(Ptr, Size));

62 return;

63 } else {

64

65

66

67 PartialUTF8Char.append(StringRef(Ptr, BytesFromBuffer));

68 ProcessUTF8CodePoint(PartialUTF8Char);

69 PartialUTF8Char.clear();

70 Ptr += BytesFromBuffer;

71 Size -= BytesFromBuffer;

72 }

73 }

74

75

76 unsigned NumBytes;

77 for (const char *End = Ptr + Size; Ptr < End; Ptr += NumBytes) {

78

79 if (*Ptr >= 0x20 && *Ptr <= 0x7e) {

80 NumBytes = 1;

81 ++Column;

82 continue;

83 }

84

86

87

88

89

90

91

92 if ((unsigned)(End - Ptr) < NumBytes) {

93 PartialUTF8Char = StringRef(Ptr, End - Ptr);

94 return;

95 }

96

97 ProcessUTF8CodePoint(StringRef(Ptr, NumBytes));

98 }

99}

100

101

102

103void formatted_raw_ostream::ComputePosition(const char *Ptr, size_t Size) {

104 if (DisableScan)

105 return;

106

107

108

109

110 if (Ptr <= Scanned && Scanned <= Ptr + Size)

111

112

113 UpdatePosition(Scanned, Size - (Scanned - Ptr));

114 else

115 UpdatePosition(Ptr, Size);

116

117

118 Scanned = Ptr + Size;

119}

120

121

122

123

124

126

128

129

131 return *this;

132}

133

134void formatted_raw_ostream::write_impl(const char *Ptr, size_t Size) {

135

136 ComputePosition(Ptr, Size);

137

138

139

141

142

143 Scanned = nullptr;

144}

145

146

147

152

153

154

159

160

161

formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...

formatted_raw_ostream & PadToColumn(unsigned NewCol)

PadToColumn - Align the output to some column number.

Definition FormattedStream.cpp:125

formatted_raw_ostream(raw_ostream &Stream)

formatted_raw_ostream - Open the specified file for writing.

raw_ostream & write(unsigned char C)

raw_ostream & indent(unsigned NumSpaces)

indent - Insert 'NumSpaces' spaces.

const char * getBufferStart() const

Return the beginning of the current stream buffer, or 0 if the stream is unbuffered.

size_t GetNumBytesInBuffer() const

@ ErrorNonPrintableCharacter

LLVM_ABI int columnWidthUTF8(StringRef Text)

Gets the number of positions the UTF8-encoded Text is likely to occupy when output on a terminal ("ch...

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI formatted_raw_ostream & fdbgs()

fdbgs() - This returns a reference to a formatted_raw_ostream for debug output.

Definition FormattedStream.cpp:162

LLVM_ABI raw_fd_ostream & outs()

This returns a reference to a raw_fd_ostream for standard output.

LLVM_ABI unsigned getNumBytesForUTF8(UTF8 firstByte)

LLVM_ABI formatted_raw_ostream & fouts()

fouts() - This returns a reference to a formatted_raw_ostream for standard output.

Definition FormattedStream.cpp:148

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

LLVM_ABI raw_fd_ostream & errs()

This returns a reference to a raw_ostream for standard error.

LLVM_ABI formatted_raw_ostream & ferrs()

ferrs() - This returns a reference to a formatted_raw_ostream for standard error.

Definition FormattedStream.cpp:155