blob: 168217381907fd851992c72d4585153bdee8f01c [file] [log] [blame]
Nick Kledzikf60a9272012-12-12 20:46:15 +00001//===- lib/Support/YAMLTraits.cpp -----------------------------------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Benjamin Kramer16132e62015-03-23 18:07:13 +000010#include "llvm/Support/YAMLTraits.h"
11#include "llvm/ADT/SmallString.h"
Nick Kledzikf60a9272012-12-12 20:46:15 +000012#include "llvm/ADT/Twine.h"
13#include "llvm/Support/Casting.h"
Benjamin Kramer16132e62015-03-23 18:07:13 +000014#include "llvm/Support/Errc.h"
Nick Kledzikf60a9272012-12-12 20:46:15 +000015#include "llvm/Support/ErrorHandling.h"
Benjamin Kramercbe05842012-12-12 20:55:44 +000016#include "llvm/Support/Format.h"
Nick Kledzikf60a9272012-12-12 20:46:15 +000017#include "llvm/Support/YAMLParser.h"
Benjamin Kramercbe05842012-12-12 20:55:44 +000018#include "llvm/Support/raw_ostream.h"
Rui Ueyama106eded2013-09-11 04:00:08 +000019#include <cctype>
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000020#include <cstring>
Benjamin Kramer36b0f122012-12-12 22:40:02 +000021using namespace llvm;
22using namespace yaml;
Nick Kledzikf60a9272012-12-12 20:46:15 +000023
24//===----------------------------------------------------------------------===//
25// IO
26//===----------------------------------------------------------------------===//
27
28IO::IO(void *Context) : Ctxt(Context) {
29}
30
31IO::~IO() {
32}
33
34void *IO::getContext() {
35 return Ctxt;
36}
37
38void IO::setContext(void *Context) {
39 Ctxt = Context;
40}
41
Nick Kledzikf60a9272012-12-12 20:46:15 +000042//===----------------------------------------------------------------------===//
43// Input
44//===----------------------------------------------------------------------===//
45
Alexander Kornienko681e37c2013-11-18 15:50:04 +000046Input::Input(StringRef InputContent,
47 void *Ctxt,
48 SourceMgr::DiagHandlerTy DiagHandler,
49 void *DiagHandlerCtxt)
Rui Ueyama38dfffa2013-09-11 00:53:07 +000050 : IO(Ctxt),
Nick Kledzik0dcef842013-01-08 21:04:44 +000051 Strm(new Stream(InputContent, SrcMgr)),
Craig Topperc10719f2014-04-07 04:17:22 +000052 CurrentNode(nullptr) {
Alexander Kornienko681e37c2013-11-18 15:50:04 +000053 if (DiagHandler)
54 SrcMgr.setDiagHandler(DiagHandler, DiagHandlerCtxt);
Nick Kledzikf60a9272012-12-12 20:46:15 +000055 DocIterator = Strm->begin();
56}
57
Nick Kledzik0dcef842013-01-08 21:04:44 +000058Input::~Input() {
Nick Kledzik0dcef842013-01-08 21:04:44 +000059}
60
Rafael Espindoladb4ed0b2014-06-13 02:24:39 +000061std::error_code Input::error() { return EC; }
Nick Kledzikf60a9272012-12-12 20:46:15 +000062
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000063// Pin the vtables to this file.
64void Input::HNode::anchor() {}
65void Input::EmptyHNode::anchor() {}
66void Input::ScalarHNode::anchor() {}
David Blaikied759fe52014-09-15 18:39:24 +000067void Input::MapHNode::anchor() {}
68void Input::SequenceHNode::anchor() {}
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000069
Nick Kledzik4761c602013-11-21 00:20:10 +000070bool Input::outputting() {
Nick Kledzikf60a9272012-12-12 20:46:15 +000071 return false;
72}
73
74bool Input::setCurrentDocument() {
Benjamin Kramer36b0f122012-12-12 22:40:02 +000075 if (DocIterator != Strm->end()) {
Nick Kledzikf60a9272012-12-12 20:46:15 +000076 Node *N = DocIterator->getRoot();
Alexander Kornienko681e37c2013-11-18 15:50:04 +000077 if (!N) {
78 assert(Strm->failed() && "Root is NULL iff parsing failed");
Rafael Espindola2a826e42014-06-13 17:20:48 +000079 EC = make_error_code(errc::invalid_argument);
Alexander Kornienko681e37c2013-11-18 15:50:04 +000080 return false;
81 }
82
Benjamin Kramer36b0f122012-12-12 22:40:02 +000083 if (isa<NullNode>(N)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +000084 // Empty files are allowed and ignored
85 ++DocIterator;
86 return setCurrentDocument();
87 }
David Blaikied759fe52014-09-15 18:39:24 +000088 TopNode = this->createHNodes(N);
Nick Kledzik0dcef842013-01-08 21:04:44 +000089 CurrentNode = TopNode.get();
Nick Kledzikf60a9272012-12-12 20:46:15 +000090 return true;
91 }
92 return false;
93}
94
Simon Atanasyanf97af8a2014-05-31 04:51:07 +000095bool Input::nextDocument() {
96 return ++DocIterator != Strm->end();
Nick Kledzikf60a9272012-12-12 20:46:15 +000097}
NAKAMURA Takumi9439c522013-11-14 07:08:49 +000098
Nick Kledzik1e6033c2013-11-14 00:59:59 +000099bool Input::mapTag(StringRef Tag, bool Default) {
NAKAMURA Takumi5b94d282013-11-14 07:08:56 +0000100 std::string foundTag = CurrentNode->_node->getVerbatimTag();
Nick Kledzik1e6033c2013-11-14 00:59:59 +0000101 if (foundTag.empty()) {
102 // If no tag found and 'Tag' is the default, say it was found.
103 return Default;
104 }
105 // Return true iff found tag matches supplied tag.
106 return Tag.equals(foundTag);
107}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000108
109void Input::beginMapping() {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000110 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000111 return;
Alexander Kornienko681e37c2013-11-18 15:50:04 +0000112 // CurrentNode can be null if the document is empty.
113 MapHNode *MN = dyn_cast_or_null<MapHNode>(CurrentNode);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000114 if (MN) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000115 MN->ValidKeys.clear();
116 }
117}
118
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000119bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault,
120 void *&SaveInfo) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000121 UseDefault = false;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000122 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000123 return false;
Alexander Kornienko681e37c2013-11-18 15:50:04 +0000124
125 // CurrentNode is null for empty documents, which is an error in case required
126 // nodes are present.
127 if (!CurrentNode) {
128 if (Required)
Rafael Espindola2a826e42014-06-13 17:20:48 +0000129 EC = make_error_code(errc::invalid_argument);
Alexander Kornienko681e37c2013-11-18 15:50:04 +0000130 return false;
131 }
132
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000133 MapHNode *MN = dyn_cast<MapHNode>(CurrentNode);
134 if (!MN) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000135 setError(CurrentNode, "not a mapping");
136 return false;
137 }
138 MN->ValidKeys.push_back(Key);
David Blaikied759fe52014-09-15 18:39:24 +0000139 HNode *Value = MN->Mapping[Key].get();
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000140 if (!Value) {
141 if (Required)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000142 setError(CurrentNode, Twine("missing required key '") + Key + "'");
143 else
144 UseDefault = true;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000145 return false;
Nick Kledzikf60a9272012-12-12 20:46:15 +0000146 }
147 SaveInfo = CurrentNode;
148 CurrentNode = Value;
149 return true;
150}
151
152void Input::postflightKey(void *saveInfo) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000153 CurrentNode = reinterpret_cast<HNode *>(saveInfo);
Nick Kledzikf60a9272012-12-12 20:46:15 +0000154}
155
156void Input::endMapping() {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000157 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000158 return;
Alexander Kornienko681e37c2013-11-18 15:50:04 +0000159 // CurrentNode can be null if the document is empty.
160 MapHNode *MN = dyn_cast_or_null<MapHNode>(CurrentNode);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000161 if (!MN)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000162 return;
Simon Atanasyan878bd8a2014-04-10 06:02:49 +0000163 for (const auto &NN : MN->Mapping) {
164 if (!MN->isValidKey(NN.first())) {
David Blaikied759fe52014-09-15 18:39:24 +0000165 setError(NN.second.get(), Twine("unknown key '") + NN.first() + "'");
Nick Kledzikf60a9272012-12-12 20:46:15 +0000166 break;
167 }
168 }
169}
170
Nick Kledzikf60a9272012-12-12 20:46:15 +0000171unsigned Input::beginSequence() {
Justin Bogner64d2cdf2015-03-02 17:26:43 +0000172 if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode))
Nick Kledzikf60a9272012-12-12 20:46:15 +0000173 return SQ->Entries.size();
Justin Bogner64d2cdf2015-03-02 17:26:43 +0000174 if (isa<EmptyHNode>(CurrentNode))
175 return 0;
176 // Treat case where there's a scalar "null" value as an empty sequence.
177 if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) {
178 if (isNull(SN->value()))
179 return 0;
Nick Kledzikf60a9272012-12-12 20:46:15 +0000180 }
Justin Bogner64d2cdf2015-03-02 17:26:43 +0000181 // Any other type of HNode is an error.
182 setError(CurrentNode, "not a sequence");
Nick Kledzikf60a9272012-12-12 20:46:15 +0000183 return 0;
184}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000185
Nick Kledzikf60a9272012-12-12 20:46:15 +0000186void Input::endSequence() {
187}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000188
Nick Kledzikf60a9272012-12-12 20:46:15 +0000189bool Input::preflightElement(unsigned Index, void *&SaveInfo) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000190 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000191 return false;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000192 if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000193 SaveInfo = CurrentNode;
David Blaikied759fe52014-09-15 18:39:24 +0000194 CurrentNode = SQ->Entries[Index].get();
Nick Kledzikf60a9272012-12-12 20:46:15 +0000195 return true;
196 }
197 return false;
198}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000199
Nick Kledzikf60a9272012-12-12 20:46:15 +0000200void Input::postflightElement(void *SaveInfo) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000201 CurrentNode = reinterpret_cast<HNode *>(SaveInfo);
Nick Kledzikf60a9272012-12-12 20:46:15 +0000202}
203
Justin Bogner64d2cdf2015-03-02 17:26:43 +0000204unsigned Input::beginFlowSequence() { return beginSequence(); }
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000205
Nick Kledzikf60a9272012-12-12 20:46:15 +0000206bool Input::preflightFlowElement(unsigned index, void *&SaveInfo) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000207 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000208 return false;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000209 if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000210 SaveInfo = CurrentNode;
David Blaikied759fe52014-09-15 18:39:24 +0000211 CurrentNode = SQ->Entries[index].get();
Nick Kledzikf60a9272012-12-12 20:46:15 +0000212 return true;
213 }
214 return false;
215}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000216
Nick Kledzikf60a9272012-12-12 20:46:15 +0000217void Input::postflightFlowElement(void *SaveInfo) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000218 CurrentNode = reinterpret_cast<HNode *>(SaveInfo);
Nick Kledzikf60a9272012-12-12 20:46:15 +0000219}
220
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000221void Input::endFlowSequence() {
222}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000223
224void Input::beginEnumScalar() {
225 ScalarMatchFound = false;
226}
227
228bool Input::matchEnumScalar(const char *Str, bool) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000229 if (ScalarMatchFound)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000230 return false;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000231 if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) {
232 if (SN->value().equals(Str)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000233 ScalarMatchFound = true;
234 return true;
235 }
236 }
237 return false;
238}
239
Michael J. Spencer731cae32015-01-23 21:57:50 +0000240bool Input::matchEnumFallback() {
241 if (ScalarMatchFound)
242 return false;
243 ScalarMatchFound = true;
244 return true;
245}
246
Nick Kledzikf60a9272012-12-12 20:46:15 +0000247void Input::endEnumScalar() {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000248 if (!ScalarMatchFound) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000249 setError(CurrentNode, "unknown enumerated scalar");
250 }
251}
252
Nick Kledzikf60a9272012-12-12 20:46:15 +0000253bool Input::beginBitSetScalar(bool &DoClear) {
254 BitValuesUsed.clear();
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000255 if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000256 BitValuesUsed.insert(BitValuesUsed.begin(), SQ->Entries.size(), false);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000257 } else {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000258 setError(CurrentNode, "expected sequence of bit values");
259 }
260 DoClear = true;
261 return true;
262}
263
264bool Input::bitSetMatch(const char *Str, bool) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000265 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000266 return false;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000267 if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000268 unsigned Index = 0;
David Blaikied759fe52014-09-15 18:39:24 +0000269 for (auto &N : SQ->Entries) {
270 if (ScalarHNode *SN = dyn_cast<ScalarHNode>(N.get())) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000271 if (SN->value().equals(Str)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000272 BitValuesUsed[Index] = true;
273 return true;
274 }
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000275 } else {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000276 setError(CurrentNode, "unexpected scalar in sequence of bit values");
277 }
278 ++Index;
279 }
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000280 } else {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000281 setError(CurrentNode, "expected sequence of bit values");
282 }
283 return false;
284}
285
286void Input::endBitSetScalar() {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000287 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000288 return;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000289 if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000290 assert(BitValuesUsed.size() == SQ->Entries.size());
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000291 for (unsigned i = 0; i < SQ->Entries.size(); ++i) {
292 if (!BitValuesUsed[i]) {
David Blaikied759fe52014-09-15 18:39:24 +0000293 setError(SQ->Entries[i].get(), "unknown bit value");
Nick Kledzikf60a9272012-12-12 20:46:15 +0000294 return;
295 }
296 }
297 }
298}
299
David Majnemer77880332014-04-10 07:37:33 +0000300void Input::scalarString(StringRef &S, bool) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000301 if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000302 S = SN->value();
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000303 } else {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000304 setError(CurrentNode, "unexpected scalar");
305 }
306}
307
308void Input::setError(HNode *hnode, const Twine &message) {
Alexander Kornienko681e37c2013-11-18 15:50:04 +0000309 assert(hnode && "HNode must not be NULL");
Nick Kledzikf60a9272012-12-12 20:46:15 +0000310 this->setError(hnode->_node, message);
311}
312
313void Input::setError(Node *node, const Twine &message) {
314 Strm->printError(node, message);
Rafael Espindola2a826e42014-06-13 17:20:48 +0000315 EC = make_error_code(errc::invalid_argument);
Nick Kledzikf60a9272012-12-12 20:46:15 +0000316}
317
David Blaikied759fe52014-09-15 18:39:24 +0000318std::unique_ptr<Input::HNode> Input::createHNodes(Node *N) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000319 SmallString<128> StringStorage;
320 if (ScalarNode *SN = dyn_cast<ScalarNode>(N)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000321 StringRef KeyStr = SN->getValue(StringStorage);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000322 if (!StringStorage.empty()) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000323 // Copy string to permanent storage
324 unsigned Len = StringStorage.size();
Nick Kledzik0dcef842013-01-08 21:04:44 +0000325 char *Buf = StringAllocator.Allocate<char>(Len);
Nick Kledzikf60a9272012-12-12 20:46:15 +0000326 memcpy(Buf, &StringStorage[0], Len);
327 KeyStr = StringRef(Buf, Len);
328 }
David Blaikied759fe52014-09-15 18:39:24 +0000329 return llvm::make_unique<ScalarHNode>(N, KeyStr);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000330 } else if (SequenceNode *SQ = dyn_cast<SequenceNode>(N)) {
David Blaikied759fe52014-09-15 18:39:24 +0000331 auto SQHNode = llvm::make_unique<SequenceHNode>(N);
Simon Atanasyan878bd8a2014-04-10 06:02:49 +0000332 for (Node &SN : *SQ) {
David Blaikied759fe52014-09-15 18:39:24 +0000333 auto Entry = this->createHNodes(&SN);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000334 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000335 break;
David Blaikied759fe52014-09-15 18:39:24 +0000336 SQHNode->Entries.push_back(std::move(Entry));
Nick Kledzikf60a9272012-12-12 20:46:15 +0000337 }
David Blaikied759fe52014-09-15 18:39:24 +0000338 return std::move(SQHNode);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000339 } else if (MappingNode *Map = dyn_cast<MappingNode>(N)) {
David Blaikied759fe52014-09-15 18:39:24 +0000340 auto mapHNode = llvm::make_unique<MapHNode>(N);
Simon Atanasyan878bd8a2014-04-10 06:02:49 +0000341 for (KeyValueNode &KVN : *Map) {
Rafael Espindolaa97373f2014-08-08 13:58:00 +0000342 Node *KeyNode = KVN.getKey();
343 ScalarNode *KeyScalar = dyn_cast<ScalarNode>(KeyNode);
344 if (!KeyScalar) {
345 setError(KeyNode, "Map key must be a scalar");
346 break;
347 }
Nick Kledzikf60a9272012-12-12 20:46:15 +0000348 StringStorage.clear();
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000349 StringRef KeyStr = KeyScalar->getValue(StringStorage);
350 if (!StringStorage.empty()) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000351 // Copy string to permanent storage
352 unsigned Len = StringStorage.size();
Nick Kledzik0dcef842013-01-08 21:04:44 +0000353 char *Buf = StringAllocator.Allocate<char>(Len);
Nick Kledzikf60a9272012-12-12 20:46:15 +0000354 memcpy(Buf, &StringStorage[0], Len);
355 KeyStr = StringRef(Buf, Len);
356 }
David Blaikied759fe52014-09-15 18:39:24 +0000357 auto ValueHNode = this->createHNodes(KVN.getValue());
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000358 if (EC)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000359 break;
David Blaikied759fe52014-09-15 18:39:24 +0000360 mapHNode->Mapping[KeyStr] = std::move(ValueHNode);
Nick Kledzikf60a9272012-12-12 20:46:15 +0000361 }
David Blaikied759fe52014-09-15 18:39:24 +0000362 return std::move(mapHNode);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000363 } else if (isa<NullNode>(N)) {
David Blaikied759fe52014-09-15 18:39:24 +0000364 return llvm::make_unique<EmptyHNode>(N);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000365 } else {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000366 setError(N, "unknown node kind");
Craig Topperc10719f2014-04-07 04:17:22 +0000367 return nullptr;
Nick Kledzikf60a9272012-12-12 20:46:15 +0000368 }
369}
370
Nick Kledzikf60a9272012-12-12 20:46:15 +0000371bool Input::MapHNode::isValidKey(StringRef Key) {
Simon Atanasyan878bd8a2014-04-10 06:02:49 +0000372 for (const char *K : ValidKeys) {
373 if (Key.equals(K))
Nick Kledzikf60a9272012-12-12 20:46:15 +0000374 return true;
375 }
376 return false;
377}
378
379void Input::setError(const Twine &Message) {
380 this->setError(CurrentNode, Message);
381}
382
Aaron Ballman0e63e532013-08-15 23:17:53 +0000383bool Input::canElideEmptySequence() {
384 return false;
385}
386
Nick Kledzikf60a9272012-12-12 20:46:15 +0000387//===----------------------------------------------------------------------===//
388// Output
389//===----------------------------------------------------------------------===//
390
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000391Output::Output(raw_ostream &yout, void *context)
392 : IO(context),
393 Out(yout),
394 Column(0),
395 ColumnAtFlowStart(0),
396 NeedBitValueComma(false),
397 NeedFlowSequenceComma(false),
398 EnumerationMatchFound(false),
399 NeedsNewLine(false) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000400}
401
402Output::~Output() {
403}
404
Nick Kledzik4761c602013-11-21 00:20:10 +0000405bool Output::outputting() {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000406 return true;
407}
408
409void Output::beginMapping() {
410 StateStack.push_back(inMapFirstKey);
411 NeedsNewLine = true;
412}
413
Nick Kledzik1e6033c2013-11-14 00:59:59 +0000414bool Output::mapTag(StringRef Tag, bool Use) {
415 if (Use) {
416 this->output(" ");
417 this->output(Tag);
418 }
419 return Use;
420}
421
Nick Kledzikf60a9272012-12-12 20:46:15 +0000422void Output::endMapping() {
423 StateStack.pop_back();
424}
425
Nick Kledzikf60a9272012-12-12 20:46:15 +0000426bool Output::preflightKey(const char *Key, bool Required, bool SameAsDefault,
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000427 bool &UseDefault, void *&) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000428 UseDefault = false;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000429 if (Required || !SameAsDefault) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000430 this->newLineCheck();
431 this->paddedKey(Key);
432 return true;
433 }
434 return false;
435}
436
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000437void Output::postflightKey(void *) {
438 if (StateStack.back() == inMapFirstKey) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000439 StateStack.pop_back();
440 StateStack.push_back(inMapOtherKey);
441 }
442}
443
444void Output::beginDocuments() {
445 this->outputUpToEndOfLine("---");
446}
447
448bool Output::preflightDocument(unsigned index) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000449 if (index > 0)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000450 this->outputUpToEndOfLine("\n---");
451 return true;
452}
453
454void Output::postflightDocument() {
455}
456
457void Output::endDocuments() {
458 output("\n...\n");
459}
460
461unsigned Output::beginSequence() {
462 StateStack.push_back(inSeq);
463 NeedsNewLine = true;
464 return 0;
465}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000466
Nick Kledzikf60a9272012-12-12 20:46:15 +0000467void Output::endSequence() {
468 StateStack.pop_back();
469}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000470
471bool Output::preflightElement(unsigned, void *&) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000472 return true;
473}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000474
475void Output::postflightElement(void *) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000476}
477
478unsigned Output::beginFlowSequence() {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000479 StateStack.push_back(inFlowSeq);
Nick Kledzik11964f22013-01-04 19:32:00 +0000480 this->newLineCheck();
Nick Kledzikf60a9272012-12-12 20:46:15 +0000481 ColumnAtFlowStart = Column;
482 output("[ ");
483 NeedFlowSequenceComma = false;
484 return 0;
485}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000486
Nick Kledzikf60a9272012-12-12 20:46:15 +0000487void Output::endFlowSequence() {
488 StateStack.pop_back();
489 this->outputUpToEndOfLine(" ]");
490}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000491
492bool Output::preflightFlowElement(unsigned, void *&) {
493 if (NeedFlowSequenceComma)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000494 output(", ");
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000495 if (Column > 70) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000496 output("\n");
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000497 for (int i = 0; i < ColumnAtFlowStart; ++i)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000498 output(" ");
499 Column = ColumnAtFlowStart;
500 output(" ");
501 }
502 return true;
503}
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000504
505void Output::postflightFlowElement(void *) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000506 NeedFlowSequenceComma = true;
507}
508
Nick Kledzikf60a9272012-12-12 20:46:15 +0000509void Output::beginEnumScalar() {
510 EnumerationMatchFound = false;
511}
512
513bool Output::matchEnumScalar(const char *Str, bool Match) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000514 if (Match && !EnumerationMatchFound) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000515 this->newLineCheck();
516 this->outputUpToEndOfLine(Str);
517 EnumerationMatchFound = true;
518 }
519 return false;
520}
521
Michael J. Spencer731cae32015-01-23 21:57:50 +0000522bool Output::matchEnumFallback() {
523 if (EnumerationMatchFound)
524 return false;
525 EnumerationMatchFound = true;
526 return true;
527}
528
Nick Kledzikf60a9272012-12-12 20:46:15 +0000529void Output::endEnumScalar() {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000530 if (!EnumerationMatchFound)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000531 llvm_unreachable("bad runtime enum value");
532}
533
Nick Kledzikf60a9272012-12-12 20:46:15 +0000534bool Output::beginBitSetScalar(bool &DoClear) {
535 this->newLineCheck();
536 output("[ ");
537 NeedBitValueComma = false;
538 DoClear = false;
539 return true;
540}
541
542bool Output::bitSetMatch(const char *Str, bool Matches) {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000543 if (Matches) {
544 if (NeedBitValueComma)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000545 output(", ");
546 this->output(Str);
547 NeedBitValueComma = true;
548 }
549 return false;
550}
551
552void Output::endBitSetScalar() {
553 this->outputUpToEndOfLine(" ]");
554}
555
David Majnemer77880332014-04-10 07:37:33 +0000556void Output::scalarString(StringRef &S, bool MustQuote) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000557 this->newLineCheck();
Rui Ueyama106eded2013-09-11 04:00:08 +0000558 if (S.empty()) {
559 // Print '' for the empty string because leaving the field empty is not
560 // allowed.
561 this->outputUpToEndOfLine("''");
562 return;
563 }
David Majnemer77880332014-04-10 07:37:33 +0000564 if (!MustQuote) {
565 // Only quote if we must.
Nick Kledzikf60a9272012-12-12 20:46:15 +0000566 this->outputUpToEndOfLine(S);
567 return;
568 }
569 unsigned i = 0;
570 unsigned j = 0;
571 unsigned End = S.size();
572 output("'"); // Starting single quote.
573 const char *Base = S.data();
574 while (j < End) {
575 // Escape a single quote by doubling it.
576 if (S[j] == '\'') {
577 output(StringRef(&Base[i], j - i + 1));
578 output("'");
579 i = j + 1;
580 }
581 ++j;
582 }
583 output(StringRef(&Base[i], j - i));
584 this->outputUpToEndOfLine("'"); // Ending single quote.
585}
586
587void Output::setError(const Twine &message) {
588}
589
Aaron Ballman0e63e532013-08-15 23:17:53 +0000590bool Output::canElideEmptySequence() {
591 // Normally, with an optional key/value where the value is an empty sequence,
592 // the whole key/value can be not written. But, that produces wrong yaml
593 // if the key/value is the only thing in the map and the map is used in
594 // a sequence. This detects if the this sequence is the first key/value
595 // in map that itself is embedded in a sequnce.
Rui Ueyama38dfffa2013-09-11 00:53:07 +0000596 if (StateStack.size() < 2)
Aaron Ballman0e63e532013-08-15 23:17:53 +0000597 return true;
Rui Ueyama38dfffa2013-09-11 00:53:07 +0000598 if (StateStack.back() != inMapFirstKey)
Aaron Ballman0e63e532013-08-15 23:17:53 +0000599 return true;
600 return (StateStack[StateStack.size()-2] != inSeq);
601}
602
Nick Kledzikf60a9272012-12-12 20:46:15 +0000603void Output::output(StringRef s) {
604 Column += s.size();
605 Out << s;
606}
607
608void Output::outputUpToEndOfLine(StringRef s) {
609 this->output(s);
Richard Smith045e4f12012-12-22 00:15:13 +0000610 if (StateStack.empty() || StateStack.back() != inFlowSeq)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000611 NeedsNewLine = true;
612}
613
614void Output::outputNewLine() {
615 Out << "\n";
616 Column = 0;
617}
618
619// if seq at top, indent as if map, then add "- "
620// if seq in middle, use "- " if firstKey, else use " "
621//
622
623void Output::newLineCheck() {
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000624 if (!NeedsNewLine)
Nick Kledzikf60a9272012-12-12 20:46:15 +0000625 return;
626 NeedsNewLine = false;
627
628 this->outputNewLine();
629
630 assert(StateStack.size() > 0);
631 unsigned Indent = StateStack.size() - 1;
632 bool OutputDash = false;
633
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000634 if (StateStack.back() == inSeq) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000635 OutputDash = true;
Alex Lorenz42e91fa2015-05-01 18:34:25 +0000636 } else if ((StateStack.size() > 1) && ((StateStack.back() == inMapFirstKey) ||
637 (StateStack.back() == inFlowSeq)) &&
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000638 (StateStack[StateStack.size() - 2] == inSeq)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000639 --Indent;
640 OutputDash = true;
641 }
642
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000643 for (unsigned i = 0; i < Indent; ++i) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000644 output(" ");
645 }
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000646 if (OutputDash) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000647 output("- ");
648 }
649
650}
651
652void Output::paddedKey(StringRef key) {
653 output(key);
654 output(":");
655 const char *spaces = " ";
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000656 if (key.size() < strlen(spaces))
Nick Kledzikf60a9272012-12-12 20:46:15 +0000657 output(&spaces[key.size()]);
658 else
659 output(" ");
660}
661
662//===----------------------------------------------------------------------===//
663// traits for built-in types
664//===----------------------------------------------------------------------===//
665
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000666void ScalarTraits<bool>::output(const bool &Val, void *, raw_ostream &Out) {
667 Out << (Val ? "true" : "false");
668}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000669
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000670StringRef ScalarTraits<bool>::input(StringRef Scalar, void *, bool &Val) {
671 if (Scalar.equals("true")) {
672 Val = true;
673 return StringRef();
674 } else if (Scalar.equals("false")) {
675 Val = false;
Nick Kledzikf60a9272012-12-12 20:46:15 +0000676 return StringRef();
677 }
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000678 return "invalid boolean";
679}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000680
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000681void ScalarTraits<StringRef>::output(const StringRef &Val, void *,
682 raw_ostream &Out) {
683 Out << Val;
684}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000685
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000686StringRef ScalarTraits<StringRef>::input(StringRef Scalar, void *,
687 StringRef &Val) {
688 Val = Scalar;
689 return StringRef();
690}
Alex Rosenbergf298f162015-01-26 18:02:18 +0000691
John Thompson48e018a2013-11-19 17:28:21 +0000692void ScalarTraits<std::string>::output(const std::string &Val, void *,
693 raw_ostream &Out) {
694 Out << Val;
695}
696
697StringRef ScalarTraits<std::string>::input(StringRef Scalar, void *,
698 std::string &Val) {
699 Val = Scalar.str();
700 return StringRef();
701}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000702
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000703void ScalarTraits<uint8_t>::output(const uint8_t &Val, void *,
704 raw_ostream &Out) {
705 // use temp uin32_t because ostream thinks uint8_t is a character
706 uint32_t Num = Val;
707 Out << Num;
708}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000709
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000710StringRef ScalarTraits<uint8_t>::input(StringRef Scalar, void *, uint8_t &Val) {
711 unsigned long long n;
712 if (getAsUnsignedInteger(Scalar, 0, n))
713 return "invalid number";
714 if (n > 0xFF)
715 return "out of range number";
716 Val = n;
717 return StringRef();
718}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000719
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000720void ScalarTraits<uint16_t>::output(const uint16_t &Val, void *,
721 raw_ostream &Out) {
722 Out << Val;
723}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000724
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000725StringRef ScalarTraits<uint16_t>::input(StringRef Scalar, void *,
726 uint16_t &Val) {
727 unsigned long long n;
728 if (getAsUnsignedInteger(Scalar, 0, n))
729 return "invalid number";
730 if (n > 0xFFFF)
731 return "out of range number";
732 Val = n;
733 return StringRef();
734}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000735
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000736void ScalarTraits<uint32_t>::output(const uint32_t &Val, void *,
737 raw_ostream &Out) {
738 Out << Val;
739}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000740
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000741StringRef ScalarTraits<uint32_t>::input(StringRef Scalar, void *,
742 uint32_t &Val) {
743 unsigned long long n;
744 if (getAsUnsignedInteger(Scalar, 0, n))
745 return "invalid number";
746 if (n > 0xFFFFFFFFUL)
747 return "out of range number";
748 Val = n;
749 return StringRef();
750}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000751
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000752void ScalarTraits<uint64_t>::output(const uint64_t &Val, void *,
753 raw_ostream &Out) {
754 Out << Val;
755}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000756
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000757StringRef ScalarTraits<uint64_t>::input(StringRef Scalar, void *,
758 uint64_t &Val) {
759 unsigned long long N;
760 if (getAsUnsignedInteger(Scalar, 0, N))
761 return "invalid number";
762 Val = N;
763 return StringRef();
764}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000765
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000766void ScalarTraits<int8_t>::output(const int8_t &Val, void *, raw_ostream &Out) {
767 // use temp in32_t because ostream thinks int8_t is a character
768 int32_t Num = Val;
769 Out << Num;
770}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000771
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000772StringRef ScalarTraits<int8_t>::input(StringRef Scalar, void *, int8_t &Val) {
773 long long N;
774 if (getAsSignedInteger(Scalar, 0, N))
775 return "invalid number";
776 if ((N > 127) || (N < -128))
777 return "out of range number";
778 Val = N;
779 return StringRef();
780}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000781
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000782void ScalarTraits<int16_t>::output(const int16_t &Val, void *,
783 raw_ostream &Out) {
784 Out << Val;
785}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000786
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000787StringRef ScalarTraits<int16_t>::input(StringRef Scalar, void *, int16_t &Val) {
788 long long N;
789 if (getAsSignedInteger(Scalar, 0, N))
790 return "invalid number";
791 if ((N > INT16_MAX) || (N < INT16_MIN))
792 return "out of range number";
793 Val = N;
794 return StringRef();
795}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000796
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000797void ScalarTraits<int32_t>::output(const int32_t &Val, void *,
798 raw_ostream &Out) {
799 Out << Val;
800}
801
802StringRef ScalarTraits<int32_t>::input(StringRef Scalar, void *, int32_t &Val) {
803 long long N;
804 if (getAsSignedInteger(Scalar, 0, N))
805 return "invalid number";
806 if ((N > INT32_MAX) || (N < INT32_MIN))
807 return "out of range number";
808 Val = N;
809 return StringRef();
810}
811
812void ScalarTraits<int64_t>::output(const int64_t &Val, void *,
813 raw_ostream &Out) {
814 Out << Val;
815}
816
817StringRef ScalarTraits<int64_t>::input(StringRef Scalar, void *, int64_t &Val) {
818 long long N;
819 if (getAsSignedInteger(Scalar, 0, N))
820 return "invalid number";
821 Val = N;
822 return StringRef();
823}
824
825void ScalarTraits<double>::output(const double &Val, void *, raw_ostream &Out) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000826 Out << format("%g", Val);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000827}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000828
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000829StringRef ScalarTraits<double>::input(StringRef Scalar, void *, double &Val) {
830 SmallString<32> buff(Scalar.begin(), Scalar.end());
831 char *end;
832 Val = strtod(buff.c_str(), &end);
833 if (*end != '\0')
834 return "invalid floating point number";
835 return StringRef();
836}
837
838void ScalarTraits<float>::output(const float &Val, void *, raw_ostream &Out) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000839 Out << format("%g", Val);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000840}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000841
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000842StringRef ScalarTraits<float>::input(StringRef Scalar, void *, float &Val) {
843 SmallString<32> buff(Scalar.begin(), Scalar.end());
844 char *end;
845 Val = strtod(buff.c_str(), &end);
846 if (*end != '\0')
847 return "invalid floating point number";
848 return StringRef();
849}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000850
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000851void ScalarTraits<Hex8>::output(const Hex8 &Val, void *, raw_ostream &Out) {
852 uint8_t Num = Val;
853 Out << format("0x%02X", Num);
854}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000855
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000856StringRef ScalarTraits<Hex8>::input(StringRef Scalar, void *, Hex8 &Val) {
857 unsigned long long n;
858 if (getAsUnsignedInteger(Scalar, 0, n))
859 return "invalid hex8 number";
860 if (n > 0xFF)
861 return "out of range hex8 number";
862 Val = n;
863 return StringRef();
864}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000865
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000866void ScalarTraits<Hex16>::output(const Hex16 &Val, void *, raw_ostream &Out) {
867 uint16_t Num = Val;
868 Out << format("0x%04X", Num);
869}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000870
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000871StringRef ScalarTraits<Hex16>::input(StringRef Scalar, void *, Hex16 &Val) {
872 unsigned long long n;
873 if (getAsUnsignedInteger(Scalar, 0, n))
874 return "invalid hex16 number";
875 if (n > 0xFFFF)
876 return "out of range hex16 number";
877 Val = n;
878 return StringRef();
879}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000880
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000881void ScalarTraits<Hex32>::output(const Hex32 &Val, void *, raw_ostream &Out) {
882 uint32_t Num = Val;
883 Out << format("0x%08X", Num);
884}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000885
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000886StringRef ScalarTraits<Hex32>::input(StringRef Scalar, void *, Hex32 &Val) {
887 unsigned long long n;
888 if (getAsUnsignedInteger(Scalar, 0, n))
889 return "invalid hex32 number";
890 if (n > 0xFFFFFFFFUL)
891 return "out of range hex32 number";
892 Val = n;
893 return StringRef();
894}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000895
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000896void ScalarTraits<Hex64>::output(const Hex64 &Val, void *, raw_ostream &Out) {
897 uint64_t Num = Val;
898 Out << format("0x%016llX", Num);
899}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000900
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000901StringRef ScalarTraits<Hex64>::input(StringRef Scalar, void *, Hex64 &Val) {
902 unsigned long long Num;
903 if (getAsUnsignedInteger(Scalar, 0, Num))
904 return "invalid hex64 number";
905 Val = Num;
906 return StringRef();
907}