blob: 74e541449f24f090b148c4b30490d750ebee0511 [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;
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000636 } else if ((StateStack.size() > 1) && (StateStack.back() == inMapFirstKey) &&
637 (StateStack[StateStack.size() - 2] == inSeq)) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000638 --Indent;
639 OutputDash = true;
640 }
641
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000642 for (unsigned i = 0; i < Indent; ++i) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000643 output(" ");
644 }
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000645 if (OutputDash) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000646 output("- ");
647 }
648
649}
650
651void Output::paddedKey(StringRef key) {
652 output(key);
653 output(":");
654 const char *spaces = " ";
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000655 if (key.size() < strlen(spaces))
Nick Kledzikf60a9272012-12-12 20:46:15 +0000656 output(&spaces[key.size()]);
657 else
658 output(" ");
659}
660
661//===----------------------------------------------------------------------===//
662// traits for built-in types
663//===----------------------------------------------------------------------===//
664
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000665void ScalarTraits<bool>::output(const bool &Val, void *, raw_ostream &Out) {
666 Out << (Val ? "true" : "false");
667}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000668
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000669StringRef ScalarTraits<bool>::input(StringRef Scalar, void *, bool &Val) {
670 if (Scalar.equals("true")) {
671 Val = true;
672 return StringRef();
673 } else if (Scalar.equals("false")) {
674 Val = false;
Nick Kledzikf60a9272012-12-12 20:46:15 +0000675 return StringRef();
676 }
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000677 return "invalid boolean";
678}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000679
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000680void ScalarTraits<StringRef>::output(const StringRef &Val, void *,
681 raw_ostream &Out) {
682 Out << Val;
683}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000684
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000685StringRef ScalarTraits<StringRef>::input(StringRef Scalar, void *,
686 StringRef &Val) {
687 Val = Scalar;
688 return StringRef();
689}
Alex Rosenbergf298f162015-01-26 18:02:18 +0000690
John Thompson48e018a2013-11-19 17:28:21 +0000691void ScalarTraits<std::string>::output(const std::string &Val, void *,
692 raw_ostream &Out) {
693 Out << Val;
694}
695
696StringRef ScalarTraits<std::string>::input(StringRef Scalar, void *,
697 std::string &Val) {
698 Val = Scalar.str();
699 return StringRef();
700}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000701
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000702void ScalarTraits<uint8_t>::output(const uint8_t &Val, void *,
703 raw_ostream &Out) {
704 // use temp uin32_t because ostream thinks uint8_t is a character
705 uint32_t Num = Val;
706 Out << Num;
707}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000708
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000709StringRef ScalarTraits<uint8_t>::input(StringRef Scalar, void *, uint8_t &Val) {
710 unsigned long long n;
711 if (getAsUnsignedInteger(Scalar, 0, n))
712 return "invalid number";
713 if (n > 0xFF)
714 return "out of range number";
715 Val = n;
716 return StringRef();
717}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000718
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000719void ScalarTraits<uint16_t>::output(const uint16_t &Val, void *,
720 raw_ostream &Out) {
721 Out << Val;
722}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000723
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000724StringRef ScalarTraits<uint16_t>::input(StringRef Scalar, void *,
725 uint16_t &Val) {
726 unsigned long long n;
727 if (getAsUnsignedInteger(Scalar, 0, n))
728 return "invalid number";
729 if (n > 0xFFFF)
730 return "out of range number";
731 Val = n;
732 return StringRef();
733}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000734
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000735void ScalarTraits<uint32_t>::output(const uint32_t &Val, void *,
736 raw_ostream &Out) {
737 Out << Val;
738}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000739
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000740StringRef ScalarTraits<uint32_t>::input(StringRef Scalar, void *,
741 uint32_t &Val) {
742 unsigned long long n;
743 if (getAsUnsignedInteger(Scalar, 0, n))
744 return "invalid number";
745 if (n > 0xFFFFFFFFUL)
746 return "out of range number";
747 Val = n;
748 return StringRef();
749}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000750
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000751void ScalarTraits<uint64_t>::output(const uint64_t &Val, void *,
752 raw_ostream &Out) {
753 Out << Val;
754}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000755
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000756StringRef ScalarTraits<uint64_t>::input(StringRef Scalar, void *,
757 uint64_t &Val) {
758 unsigned long long N;
759 if (getAsUnsignedInteger(Scalar, 0, N))
760 return "invalid number";
761 Val = N;
762 return StringRef();
763}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000764
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000765void ScalarTraits<int8_t>::output(const int8_t &Val, void *, raw_ostream &Out) {
766 // use temp in32_t because ostream thinks int8_t is a character
767 int32_t Num = Val;
768 Out << Num;
769}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000770
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000771StringRef ScalarTraits<int8_t>::input(StringRef Scalar, void *, int8_t &Val) {
772 long long N;
773 if (getAsSignedInteger(Scalar, 0, N))
774 return "invalid number";
775 if ((N > 127) || (N < -128))
776 return "out of range number";
777 Val = N;
778 return StringRef();
779}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000780
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000781void ScalarTraits<int16_t>::output(const int16_t &Val, void *,
782 raw_ostream &Out) {
783 Out << Val;
784}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000785
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000786StringRef ScalarTraits<int16_t>::input(StringRef Scalar, void *, int16_t &Val) {
787 long long N;
788 if (getAsSignedInteger(Scalar, 0, N))
789 return "invalid number";
790 if ((N > INT16_MAX) || (N < INT16_MIN))
791 return "out of range number";
792 Val = N;
793 return StringRef();
794}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000795
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000796void ScalarTraits<int32_t>::output(const int32_t &Val, void *,
797 raw_ostream &Out) {
798 Out << Val;
799}
800
801StringRef ScalarTraits<int32_t>::input(StringRef Scalar, void *, int32_t &Val) {
802 long long N;
803 if (getAsSignedInteger(Scalar, 0, N))
804 return "invalid number";
805 if ((N > INT32_MAX) || (N < INT32_MIN))
806 return "out of range number";
807 Val = N;
808 return StringRef();
809}
810
811void ScalarTraits<int64_t>::output(const int64_t &Val, void *,
812 raw_ostream &Out) {
813 Out << Val;
814}
815
816StringRef ScalarTraits<int64_t>::input(StringRef Scalar, void *, int64_t &Val) {
817 long long N;
818 if (getAsSignedInteger(Scalar, 0, N))
819 return "invalid number";
820 Val = N;
821 return StringRef();
822}
823
824void ScalarTraits<double>::output(const double &Val, void *, raw_ostream &Out) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000825 Out << format("%g", Val);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000826}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000827
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000828StringRef ScalarTraits<double>::input(StringRef Scalar, void *, double &Val) {
829 SmallString<32> buff(Scalar.begin(), Scalar.end());
830 char *end;
831 Val = strtod(buff.c_str(), &end);
832 if (*end != '\0')
833 return "invalid floating point number";
834 return StringRef();
835}
836
837void ScalarTraits<float>::output(const float &Val, void *, raw_ostream &Out) {
Nick Kledzikf60a9272012-12-12 20:46:15 +0000838 Out << format("%g", Val);
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000839}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000840
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000841StringRef ScalarTraits<float>::input(StringRef Scalar, void *, float &Val) {
842 SmallString<32> buff(Scalar.begin(), Scalar.end());
843 char *end;
844 Val = strtod(buff.c_str(), &end);
845 if (*end != '\0')
846 return "invalid floating point number";
847 return StringRef();
848}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000849
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000850void ScalarTraits<Hex8>::output(const Hex8 &Val, void *, raw_ostream &Out) {
851 uint8_t Num = Val;
852 Out << format("0x%02X", Num);
853}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000854
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000855StringRef ScalarTraits<Hex8>::input(StringRef Scalar, void *, Hex8 &Val) {
856 unsigned long long n;
857 if (getAsUnsignedInteger(Scalar, 0, n))
858 return "invalid hex8 number";
859 if (n > 0xFF)
860 return "out of range hex8 number";
861 Val = n;
862 return StringRef();
863}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000864
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000865void ScalarTraits<Hex16>::output(const Hex16 &Val, void *, raw_ostream &Out) {
866 uint16_t Num = Val;
867 Out << format("0x%04X", Num);
868}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000869
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000870StringRef ScalarTraits<Hex16>::input(StringRef Scalar, void *, Hex16 &Val) {
871 unsigned long long n;
872 if (getAsUnsignedInteger(Scalar, 0, n))
873 return "invalid hex16 number";
874 if (n > 0xFFFF)
875 return "out of range hex16 number";
876 Val = n;
877 return StringRef();
878}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000879
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000880void ScalarTraits<Hex32>::output(const Hex32 &Val, void *, raw_ostream &Out) {
881 uint32_t Num = Val;
882 Out << format("0x%08X", Num);
883}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000884
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000885StringRef ScalarTraits<Hex32>::input(StringRef Scalar, void *, Hex32 &Val) {
886 unsigned long long n;
887 if (getAsUnsignedInteger(Scalar, 0, n))
888 return "invalid hex32 number";
889 if (n > 0xFFFFFFFFUL)
890 return "out of range hex32 number";
891 Val = n;
892 return StringRef();
893}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000894
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000895void ScalarTraits<Hex64>::output(const Hex64 &Val, void *, raw_ostream &Out) {
896 uint64_t Num = Val;
897 Out << format("0x%016llX", Num);
898}
Nick Kledzikf60a9272012-12-12 20:46:15 +0000899
Benjamin Kramer36b0f122012-12-12 22:40:02 +0000900StringRef ScalarTraits<Hex64>::input(StringRef Scalar, void *, Hex64 &Val) {
901 unsigned long long Num;
902 if (getAsUnsignedInteger(Scalar, 0, Num))
903 return "invalid hex64 number";
904 Val = Num;
905 return StringRef();
906}