llvm.org GIT mirror llvm / 96b4005
Reverting my r193344 checkin due to build breakage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193350 91177308-0d34-0410-b5e6-96231b3b80d8 John Thompson 5 years ago
4 changed file(s) with 1 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
233233 * float
234234 * double
235235 * StringRef
236 * std::string
237236 * int64_t
238237 * int32_t
239238 * int16_t
None //===- llvm/Support/YAMLTraits.h -------------------------------*- C++ -*-===//
0 //===- llvm/Supporrt/YAMLTraits.h -------------------------------*- C++ -*-===//
11 //
22 // The LLVM Linker
33 //
535535 struct ScalarTraits {
536536 static void output(const StringRef &, void*, llvm::raw_ostream &);
537537 static StringRef input(StringRef, void*, StringRef &);
538 };
539
540 template<>
541 struct ScalarTraits {
542 static void output(const std::string &, void*, llvm::raw_ostream &);
543 static StringRef input(StringRef, void*, std::string &);
544538 };
545539
546540 template<>
647647 return StringRef();
648648 }
649649
650 void ScalarTraits::output(const std::string &Val, void *,
651 raw_ostream &Out) {
652 Out << Val;
653 }
654
655 StringRef ScalarTraits::input(StringRef Scalar, void *,
656 std::string &Val) {
657 Val = Scalar.str();
658 return StringRef();
659 }
660
661650 void ScalarTraits::output(const uint8_t &Val, void *,
662651 raw_ostream &Out) {
663652 // use temp uin32_t because ostream thinks uint8_t is a character
129129
130130 struct BuiltInTypes {
131131 llvm::StringRef str;
132 std::string stdstr;
133132 uint64_t u64;
134133 uint32_t u32;
135134 uint16_t u16;
153152 struct MappingTraits {
154153 static void mapping(IO &io, BuiltInTypes& bt) {
155154 io.mapRequired("str", bt.str);
156 io.mapRequired("stdstr", bt.stdstr);
157155 io.mapRequired("u64", bt.u64);
158156 io.mapRequired("u32", bt.u32);
159157 io.mapRequired("u16", bt.u16);
182180 BuiltInTypes map;
183181 Input yin("---\n"
184182 "str: hello there\n"
185 "stdstr: hello where?\n"
186183 "u64: 5000000000\n"
187184 "u32: 4000000000\n"
188185 "u16: 65000\n"
203200
204201 EXPECT_FALSE(yin.error());
205202 EXPECT_TRUE(map.str.equals("hello there"));
206 EXPECT_TRUE(map.stdstr == "hello where?");
207203 EXPECT_EQ(map.u64, 5000000000ULL);
208204 EXPECT_EQ(map.u32, 4000000000U);
209205 EXPECT_EQ(map.u16, 65000);
230226 {
231227 BuiltInTypes map;
232228 map.str = "one two";
233 map.stdstr = "three four";
234229 map.u64 = 6000000000ULL;
235230 map.u32 = 3000000000U;
236231 map.u16 = 50000;
259254
260255 EXPECT_FALSE(yin.error());
261256 EXPECT_TRUE(map.str.equals("one two"));
262 EXPECT_TRUE(map.stdstr == "three four");
263257 EXPECT_EQ(map.u64, 6000000000ULL);
264258 EXPECT_EQ(map.u32, 3000000000U);
265259 EXPECT_EQ(map.u16, 50000);
284278 llvm::StringRef str3;
285279 llvm::StringRef str4;
286280 llvm::StringRef str5;
287 std::string stdstr1;
288 std::string stdstr2;
289 std::string stdstr3;
290 std::string stdstr4;
291 std::string stdstr5;
292281 };
293282
294283 namespace llvm {
301290 io.mapRequired("str3", st.str3);
302291 io.mapRequired("str4", st.str4);
303292 io.mapRequired("str5", st.str5);
304 io.mapRequired("stdstr1", st.stdstr1);
305 io.mapRequired("stdstr2", st.stdstr2);
306 io.mapRequired("stdstr3", st.stdstr3);
307 io.mapRequired("stdstr4", st.stdstr4);
308 io.mapRequired("stdstr5", st.stdstr5);
309293 }
310294 };
311295 }
320304 map.str3 = "`ccc";
321305 map.str4 = "@ddd";
322306 map.str5 = "";
323 map.stdstr1 = "'eee";
324 map.stdstr2 = "\"fff";
325 map.stdstr3 = "`ggg";
326 map.stdstr4 = "@hhh";
327 map.stdstr5 = "";
328307
329308 llvm::raw_string_ostream ostr(intermediate);
330309 Output yout(ostr);
337316 EXPECT_NE(llvm::StringRef::npos, flowOut.find("'`ccc'"));
338317 EXPECT_NE(llvm::StringRef::npos, flowOut.find("'@ddd'"));
339318 EXPECT_NE(llvm::StringRef::npos, flowOut.find("''\n"));
340 EXPECT_NE(std::string::npos, flowOut.find("'''eee"));
341 EXPECT_NE(std::string::npos, flowOut.find("'\"fff'"));
342 EXPECT_NE(std::string::npos, flowOut.find("'`ggg'"));
343 EXPECT_NE(std::string::npos, flowOut.find("'@hhh'"));
344 EXPECT_NE(std::string::npos, flowOut.find("''\n"));
345319
346320 {
347321 Input yin(intermediate);
354328 EXPECT_TRUE(map.str3.equals("`ccc"));
355329 EXPECT_TRUE(map.str4.equals("@ddd"));
356330 EXPECT_TRUE(map.str5.equals(""));
357 EXPECT_TRUE(map.stdstr1 == "'eee");
358 EXPECT_TRUE(map.stdstr2 == "\"fff");
359 EXPECT_TRUE(map.stdstr3 == "`ggg");
360 EXPECT_TRUE(map.stdstr4 == "@hhh");
361 EXPECT_TRUE(map.stdstr5 == "");
362331 }
363332 }
364333