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

1

2

3

4

5

6

7

8

11#include "llvm/Config/llvm-config.h"

15using namespace llvm;

16

18

19 if (LHSKind == StdStringKind && RHSKind == EmptyKind)

20 return *LHS.stdString;

21

22

23

24 if (LHSKind == FormatvObjectKind && RHSKind == EmptyKind)

25 return LHS.formatvObject->str();

26

27

30}

31

36

38 if (isUnary()) {

39 switch (getLHSKind()) {

40 case CStringKind:

41

43 case StdStringKind: {

44 const std::string *str = LHS.stdString;

46 }

47 case StringLiteralKind:

48 return StringRef(LHS.ptrAndLength.ptr, LHS.ptrAndLength.length);

49 default:

50 break;

51 }

52 }

57}

58

59void Twine::printOneChild(raw_ostream &OS, Child Ptr, NodeKind Kind) const {

60 switch (Kind) {

61 case Twine::NullKind:

62 break;

63 case Twine::EmptyKind:

64 break;

65 case Twine::TwineKind:

66 Ptr.twine->print(OS);

67 break;

68 case Twine::CStringKind:

69 OS << Ptr.cString;

70 break;

71 case Twine::StdStringKind:

72 OS << *Ptr.stdString;

73 break;

74 case Twine::PtrAndLengthKind:

75 case Twine::StringLiteralKind:

76 OS << StringRef(Ptr.ptrAndLength.ptr, Ptr.ptrAndLength.length);

77 break;

78 case Twine::FormatvObjectKind:

79 OS << *Ptr.formatvObject;

80 break;

81 case Twine::CharKind:

82 OS << Ptr.character;

83 break;

84 case Twine::DecUIKind:

85 OS << Ptr.decUI;

86 break;

87 case Twine::DecIKind:

88 OS << Ptr.decI;

89 break;

90 case Twine::DecULKind:

91 OS << Ptr.decUL;

92 break;

93 case Twine::DecLKind:

94 OS << Ptr.decL;

95 break;

96 case Twine::DecULLKind:

97 OS << Ptr.decULL;

98 break;

99 case Twine::DecLLKind:

100 OS << Ptr.decLL;

101 break;

102 case Twine::UHexKind:

104 break;

105 }

106}

107

108void Twine::printOneChildRepr(raw_ostream &OS, Child Ptr, NodeKind Kind) const {

109 switch (Kind) {

110 case Twine::NullKind:

111 OS << "null";

112 break;

113 case Twine::EmptyKind:

114 OS << "empty";

115 break;

116 case Twine::TwineKind:

117 OS << "rope:";

118 Ptr.twine->printRepr(OS);

119 break;

120 case Twine::CStringKind:

121 OS << "cstring:\"" << Ptr.cString << "\"";

122 break;

123 case Twine::StdStringKind:

124 OS << "std:🧵\"" << Ptr.stdString << "\"";

125 break;

126 case Twine::PtrAndLengthKind:

127 OS << "ptrAndLength:\""

128 << StringRef(Ptr.ptrAndLength.ptr, Ptr.ptrAndLength.length) << "\"";

129 break;

130 case Twine::StringLiteralKind:

131 OS << "constexprPtrAndLength:\""

132 << StringRef(Ptr.ptrAndLength.ptr, Ptr.ptrAndLength.length) << "\"";

133 break;

134 case Twine::FormatvObjectKind:

135 OS << "formatv:\"" << *Ptr.formatvObject << "\"";

136 break;

137 case Twine::CharKind:

138 OS << "char:\"" << Ptr.character << "\"";

139 break;

140 case Twine::DecUIKind:

141 OS << "decUI:\"" << Ptr.decUI << "\"";

142 break;

143 case Twine::DecIKind:

144 OS << "decI:\"" << Ptr.decI << "\"";

145 break;

146 case Twine::DecULKind:

147 OS << "decUL:\"" << Ptr.decUL << "\"";

148 break;

149 case Twine::DecLKind:

150 OS << "decL:\"" << Ptr.decL << "\"";

151 break;

152 case Twine::DecULLKind:

153 OS << "decULL:\"" << Ptr.decULL << "\"";

154 break;

155 case Twine::DecLLKind:

156 OS << "decLL:\"" << Ptr.decLL << "\"";

157 break;

158 case Twine::UHexKind:

159 OS << "uhex:\"" << Ptr.uHex << "\"";

160 break;

161 }

162}

163

165 printOneChild(OS, LHS, getLHSKind());

166 printOneChild(OS, RHS, getRHSKind());

167}

168

170 OS << "(Twine ";

171 printOneChildRepr(OS, LHS, getLHSKind());

172 OS << " ";

173 printOneChildRepr(OS, RHS, getRHSKind());

174 OS << ")";

175}

176

177#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

179

181#endif

#define LLVM_DUMP_METHOD

Mark debug helper function definitions like dump() that should not be stripped from debug builds.

This file defines the SmallString class.

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

void push_back(const T &Elt)

pointer data()

Return a pointer to the vector's buffer, even if empty().

StringRef - Represent a constant reference to a string, i.e.

std::string str() const

str - Get the contents as an std::string.

LLVM_ABI std::string str() const

Return the twine contents as a std::string.

Definition Twine.cpp:17

LLVM_ABI void print(raw_ostream &OS) const

Write the concatenated string represented by this twine to the stream OS.

Definition Twine.cpp:164

LLVM_ABI StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const

This returns the twine as a single null terminated StringRef if it can be represented as such.

Definition Twine.cpp:37

LLVM_DUMP_METHOD void dump() const

Dump the concatenated string represented by this twine to stderr.

Definition Twine.cpp:178

LLVM_ABI void printRepr(raw_ostream &OS) const

Write the representation of this twine to the stream OS.

Definition Twine.cpp:169

StringRef toStringRef(SmallVectorImpl< char > &Out) const

This returns the twine as a single StringRef if it can be represented as such.

LLVM_ABI void toVector(SmallVectorImpl< char > &Out) const

Append the concatenated string into the given SmallString or SmallVector.

Definition Twine.cpp:32

LLVM_DUMP_METHOD void dumpRepr() const

Dump the representation of this twine to stderr.

Definition Twine.cpp:180

This class implements an extremely fast bulk output stream that can only output to a stream.

raw_ostream & write_hex(unsigned long long N)

Output N in hexadecimal, without any prefix or padding.

A raw_ostream that writes to an SmallVector or SmallString.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI raw_ostream & dbgs()

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

Determine the kind of a node from its type.