Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 1 | //===- 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 Kramer | 16132e6 | 2015-03-23 18:07:13 +0000 | [diff] [blame] | 10 | #include "llvm/Support/YAMLTraits.h" |
| 11 | #include "llvm/ADT/SmallString.h" |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/Twine.h" |
| 13 | #include "llvm/Support/Casting.h" |
Benjamin Kramer | 16132e6 | 2015-03-23 18:07:13 +0000 | [diff] [blame] | 14 | #include "llvm/Support/Errc.h" |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 15 | #include "llvm/Support/ErrorHandling.h" |
Benjamin Kramer | cbe0584 | 2012-12-12 20:55:44 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Format.h" |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 17 | #include "llvm/Support/YAMLParser.h" |
Benjamin Kramer | cbe0584 | 2012-12-12 20:55:44 +0000 | [diff] [blame] | 18 | #include "llvm/Support/raw_ostream.h" |
Rui Ueyama | 106eded | 2013-09-11 04:00:08 +0000 | [diff] [blame] | 19 | #include <cctype> |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 20 | #include <cstring> |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | using namespace yaml; |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | // IO |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
| 28 | IO::IO(void *Context) : Ctxt(Context) { |
| 29 | } |
| 30 | |
| 31 | IO::~IO() { |
| 32 | } |
| 33 | |
| 34 | void *IO::getContext() { |
| 35 | return Ctxt; |
| 36 | } |
| 37 | |
| 38 | void IO::setContext(void *Context) { |
| 39 | Ctxt = Context; |
| 40 | } |
| 41 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 42 | //===----------------------------------------------------------------------===// |
| 43 | // Input |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 46 | Input::Input(StringRef InputContent, |
| 47 | void *Ctxt, |
| 48 | SourceMgr::DiagHandlerTy DiagHandler, |
| 49 | void *DiagHandlerCtxt) |
Rui Ueyama | 38dfffa | 2013-09-11 00:53:07 +0000 | [diff] [blame] | 50 | : IO(Ctxt), |
Nick Kledzik | 0dcef84 | 2013-01-08 21:04:44 +0000 | [diff] [blame] | 51 | Strm(new Stream(InputContent, SrcMgr)), |
Craig Topper | c10719f | 2014-04-07 04:17:22 +0000 | [diff] [blame] | 52 | CurrentNode(nullptr) { |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 53 | if (DiagHandler) |
| 54 | SrcMgr.setDiagHandler(DiagHandler, DiagHandlerCtxt); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 55 | DocIterator = Strm->begin(); |
| 56 | } |
| 57 | |
Nick Kledzik | 0dcef84 | 2013-01-08 21:04:44 +0000 | [diff] [blame] | 58 | Input::~Input() { |
Nick Kledzik | 0dcef84 | 2013-01-08 21:04:44 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Rafael Espindola | db4ed0b | 2014-06-13 02:24:39 +0000 | [diff] [blame] | 61 | std::error_code Input::error() { return EC; } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 62 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 63 | // Pin the vtables to this file. |
| 64 | void Input::HNode::anchor() {} |
| 65 | void Input::EmptyHNode::anchor() {} |
| 66 | void Input::ScalarHNode::anchor() {} |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 67 | void Input::MapHNode::anchor() {} |
| 68 | void Input::SequenceHNode::anchor() {} |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 69 | |
Nick Kledzik | 4761c60 | 2013-11-21 00:20:10 +0000 | [diff] [blame] | 70 | bool Input::outputting() { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 71 | return false; |
| 72 | } |
| 73 | |
| 74 | bool Input::setCurrentDocument() { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 75 | if (DocIterator != Strm->end()) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 76 | Node *N = DocIterator->getRoot(); |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 77 | if (!N) { |
| 78 | assert(Strm->failed() && "Root is NULL iff parsing failed"); |
Rafael Espindola | 2a826e4 | 2014-06-13 17:20:48 +0000 | [diff] [blame] | 79 | EC = make_error_code(errc::invalid_argument); |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 80 | return false; |
| 81 | } |
| 82 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 83 | if (isa<NullNode>(N)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 84 | // Empty files are allowed and ignored |
| 85 | ++DocIterator; |
| 86 | return setCurrentDocument(); |
| 87 | } |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 88 | TopNode = this->createHNodes(N); |
Nick Kledzik | 0dcef84 | 2013-01-08 21:04:44 +0000 | [diff] [blame] | 89 | CurrentNode = TopNode.get(); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 90 | return true; |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
Simon Atanasyan | f97af8a | 2014-05-31 04:51:07 +0000 | [diff] [blame] | 95 | bool Input::nextDocument() { |
| 96 | return ++DocIterator != Strm->end(); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 97 | } |
NAKAMURA Takumi | 9439c52 | 2013-11-14 07:08:49 +0000 | [diff] [blame] | 98 | |
Nick Kledzik | 1e6033c | 2013-11-14 00:59:59 +0000 | [diff] [blame] | 99 | bool Input::mapTag(StringRef Tag, bool Default) { |
NAKAMURA Takumi | 5b94d28 | 2013-11-14 07:08:56 +0000 | [diff] [blame] | 100 | std::string foundTag = CurrentNode->_node->getVerbatimTag(); |
Nick Kledzik | 1e6033c | 2013-11-14 00:59:59 +0000 | [diff] [blame] | 101 | 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 Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 108 | |
| 109 | void Input::beginMapping() { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 110 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 111 | return; |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 112 | // CurrentNode can be null if the document is empty. |
| 113 | MapHNode *MN = dyn_cast_or_null<MapHNode>(CurrentNode); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 114 | if (MN) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 115 | MN->ValidKeys.clear(); |
| 116 | } |
| 117 | } |
| 118 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 119 | bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault, |
| 120 | void *&SaveInfo) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 121 | UseDefault = false; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 122 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 123 | return false; |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 124 | |
| 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 Espindola | 2a826e4 | 2014-06-13 17:20:48 +0000 | [diff] [blame] | 129 | EC = make_error_code(errc::invalid_argument); |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 130 | return false; |
| 131 | } |
| 132 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 133 | MapHNode *MN = dyn_cast<MapHNode>(CurrentNode); |
| 134 | if (!MN) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 135 | setError(CurrentNode, "not a mapping"); |
| 136 | return false; |
| 137 | } |
| 138 | MN->ValidKeys.push_back(Key); |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 139 | HNode *Value = MN->Mapping[Key].get(); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 140 | if (!Value) { |
| 141 | if (Required) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 142 | setError(CurrentNode, Twine("missing required key '") + Key + "'"); |
| 143 | else |
| 144 | UseDefault = true; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 145 | return false; |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 146 | } |
| 147 | SaveInfo = CurrentNode; |
| 148 | CurrentNode = Value; |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | void Input::postflightKey(void *saveInfo) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 153 | CurrentNode = reinterpret_cast<HNode *>(saveInfo); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void Input::endMapping() { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 157 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 158 | return; |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 159 | // CurrentNode can be null if the document is empty. |
| 160 | MapHNode *MN = dyn_cast_or_null<MapHNode>(CurrentNode); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 161 | if (!MN) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 162 | return; |
Simon Atanasyan | 878bd8a | 2014-04-10 06:02:49 +0000 | [diff] [blame] | 163 | for (const auto &NN : MN->Mapping) { |
| 164 | if (!MN->isValidKey(NN.first())) { |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 165 | setError(NN.second.get(), Twine("unknown key '") + NN.first() + "'"); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 166 | break; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
Alex Lorenz | b122508 | 2015-05-04 20:11:40 +0000 | [diff] [blame] | 171 | void Input::beginFlowMapping() { beginMapping(); } |
| 172 | |
| 173 | void Input::endFlowMapping() { endMapping(); } |
| 174 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 175 | unsigned Input::beginSequence() { |
Justin Bogner | 64d2cdf | 2015-03-02 17:26:43 +0000 | [diff] [blame] | 176 | if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 177 | return SQ->Entries.size(); |
Justin Bogner | 64d2cdf | 2015-03-02 17:26:43 +0000 | [diff] [blame] | 178 | if (isa<EmptyHNode>(CurrentNode)) |
| 179 | return 0; |
| 180 | // Treat case where there's a scalar "null" value as an empty sequence. |
| 181 | if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) { |
| 182 | if (isNull(SN->value())) |
| 183 | return 0; |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 184 | } |
Justin Bogner | 64d2cdf | 2015-03-02 17:26:43 +0000 | [diff] [blame] | 185 | // Any other type of HNode is an error. |
| 186 | setError(CurrentNode, "not a sequence"); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 187 | return 0; |
| 188 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 189 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 190 | void Input::endSequence() { |
| 191 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 192 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 193 | bool Input::preflightElement(unsigned Index, void *&SaveInfo) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 194 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 195 | return false; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 196 | if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 197 | SaveInfo = CurrentNode; |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 198 | CurrentNode = SQ->Entries[Index].get(); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 199 | return true; |
| 200 | } |
| 201 | return false; |
| 202 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 203 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 204 | void Input::postflightElement(void *SaveInfo) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 205 | CurrentNode = reinterpret_cast<HNode *>(SaveInfo); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Justin Bogner | 64d2cdf | 2015-03-02 17:26:43 +0000 | [diff] [blame] | 208 | unsigned Input::beginFlowSequence() { return beginSequence(); } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 209 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 210 | bool Input::preflightFlowElement(unsigned index, void *&SaveInfo) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 211 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 212 | return false; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 213 | if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 214 | SaveInfo = CurrentNode; |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 215 | CurrentNode = SQ->Entries[index].get(); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 216 | return true; |
| 217 | } |
| 218 | return false; |
| 219 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 220 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 221 | void Input::postflightFlowElement(void *SaveInfo) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 222 | CurrentNode = reinterpret_cast<HNode *>(SaveInfo); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 225 | void Input::endFlowSequence() { |
| 226 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 227 | |
| 228 | void Input::beginEnumScalar() { |
| 229 | ScalarMatchFound = false; |
| 230 | } |
| 231 | |
| 232 | bool Input::matchEnumScalar(const char *Str, bool) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 233 | if (ScalarMatchFound) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 234 | return false; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 235 | if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) { |
| 236 | if (SN->value().equals(Str)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 237 | ScalarMatchFound = true; |
| 238 | return true; |
| 239 | } |
| 240 | } |
| 241 | return false; |
| 242 | } |
| 243 | |
Michael J. Spencer | 731cae3 | 2015-01-23 21:57:50 +0000 | [diff] [blame] | 244 | bool Input::matchEnumFallback() { |
| 245 | if (ScalarMatchFound) |
| 246 | return false; |
| 247 | ScalarMatchFound = true; |
| 248 | return true; |
| 249 | } |
| 250 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 251 | void Input::endEnumScalar() { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 252 | if (!ScalarMatchFound) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 253 | setError(CurrentNode, "unknown enumerated scalar"); |
| 254 | } |
| 255 | } |
| 256 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 257 | bool Input::beginBitSetScalar(bool &DoClear) { |
| 258 | BitValuesUsed.clear(); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 259 | if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 260 | BitValuesUsed.insert(BitValuesUsed.begin(), SQ->Entries.size(), false); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 261 | } else { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 262 | setError(CurrentNode, "expected sequence of bit values"); |
| 263 | } |
| 264 | DoClear = true; |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | bool Input::bitSetMatch(const char *Str, bool) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 269 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 270 | return false; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 271 | if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 272 | unsigned Index = 0; |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 273 | for (auto &N : SQ->Entries) { |
| 274 | if (ScalarHNode *SN = dyn_cast<ScalarHNode>(N.get())) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 275 | if (SN->value().equals(Str)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 276 | BitValuesUsed[Index] = true; |
| 277 | return true; |
| 278 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 279 | } else { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 280 | setError(CurrentNode, "unexpected scalar in sequence of bit values"); |
| 281 | } |
| 282 | ++Index; |
| 283 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 284 | } else { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 285 | setError(CurrentNode, "expected sequence of bit values"); |
| 286 | } |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | void Input::endBitSetScalar() { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 291 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 292 | return; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 293 | if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 294 | assert(BitValuesUsed.size() == SQ->Entries.size()); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 295 | for (unsigned i = 0; i < SQ->Entries.size(); ++i) { |
| 296 | if (!BitValuesUsed[i]) { |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 297 | setError(SQ->Entries[i].get(), "unknown bit value"); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 298 | return; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
David Majnemer | 7788033 | 2014-04-10 07:37:33 +0000 | [diff] [blame] | 304 | void Input::scalarString(StringRef &S, bool) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 305 | if (ScalarHNode *SN = dyn_cast<ScalarHNode>(CurrentNode)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 306 | S = SN->value(); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 307 | } else { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 308 | setError(CurrentNode, "unexpected scalar"); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | void Input::setError(HNode *hnode, const Twine &message) { |
Alexander Kornienko | 681e37c | 2013-11-18 15:50:04 +0000 | [diff] [blame] | 313 | assert(hnode && "HNode must not be NULL"); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 314 | this->setError(hnode->_node, message); |
| 315 | } |
| 316 | |
| 317 | void Input::setError(Node *node, const Twine &message) { |
| 318 | Strm->printError(node, message); |
Rafael Espindola | 2a826e4 | 2014-06-13 17:20:48 +0000 | [diff] [blame] | 319 | EC = make_error_code(errc::invalid_argument); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 320 | } |
| 321 | |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 322 | std::unique_ptr<Input::HNode> Input::createHNodes(Node *N) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 323 | SmallString<128> StringStorage; |
| 324 | if (ScalarNode *SN = dyn_cast<ScalarNode>(N)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 325 | StringRef KeyStr = SN->getValue(StringStorage); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 326 | if (!StringStorage.empty()) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 327 | // Copy string to permanent storage |
| 328 | unsigned Len = StringStorage.size(); |
Nick Kledzik | 0dcef84 | 2013-01-08 21:04:44 +0000 | [diff] [blame] | 329 | char *Buf = StringAllocator.Allocate<char>(Len); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 330 | memcpy(Buf, &StringStorage[0], Len); |
| 331 | KeyStr = StringRef(Buf, Len); |
| 332 | } |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 333 | return llvm::make_unique<ScalarHNode>(N, KeyStr); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 334 | } else if (SequenceNode *SQ = dyn_cast<SequenceNode>(N)) { |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 335 | auto SQHNode = llvm::make_unique<SequenceHNode>(N); |
Simon Atanasyan | 878bd8a | 2014-04-10 06:02:49 +0000 | [diff] [blame] | 336 | for (Node &SN : *SQ) { |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 337 | auto Entry = this->createHNodes(&SN); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 338 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 339 | break; |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 340 | SQHNode->Entries.push_back(std::move(Entry)); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 341 | } |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 342 | return std::move(SQHNode); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 343 | } else if (MappingNode *Map = dyn_cast<MappingNode>(N)) { |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 344 | auto mapHNode = llvm::make_unique<MapHNode>(N); |
Simon Atanasyan | 878bd8a | 2014-04-10 06:02:49 +0000 | [diff] [blame] | 345 | for (KeyValueNode &KVN : *Map) { |
Rafael Espindola | a97373f | 2014-08-08 13:58:00 +0000 | [diff] [blame] | 346 | Node *KeyNode = KVN.getKey(); |
| 347 | ScalarNode *KeyScalar = dyn_cast<ScalarNode>(KeyNode); |
| 348 | if (!KeyScalar) { |
| 349 | setError(KeyNode, "Map key must be a scalar"); |
| 350 | break; |
| 351 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 352 | StringStorage.clear(); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 353 | StringRef KeyStr = KeyScalar->getValue(StringStorage); |
| 354 | if (!StringStorage.empty()) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 355 | // Copy string to permanent storage |
| 356 | unsigned Len = StringStorage.size(); |
Nick Kledzik | 0dcef84 | 2013-01-08 21:04:44 +0000 | [diff] [blame] | 357 | char *Buf = StringAllocator.Allocate<char>(Len); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 358 | memcpy(Buf, &StringStorage[0], Len); |
| 359 | KeyStr = StringRef(Buf, Len); |
| 360 | } |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 361 | auto ValueHNode = this->createHNodes(KVN.getValue()); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 362 | if (EC) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 363 | break; |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 364 | mapHNode->Mapping[KeyStr] = std::move(ValueHNode); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 365 | } |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 366 | return std::move(mapHNode); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 367 | } else if (isa<NullNode>(N)) { |
David Blaikie | d759fe5 | 2014-09-15 18:39:24 +0000 | [diff] [blame] | 368 | return llvm::make_unique<EmptyHNode>(N); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 369 | } else { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 370 | setError(N, "unknown node kind"); |
Craig Topper | c10719f | 2014-04-07 04:17:22 +0000 | [diff] [blame] | 371 | return nullptr; |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 375 | bool Input::MapHNode::isValidKey(StringRef Key) { |
Simon Atanasyan | 878bd8a | 2014-04-10 06:02:49 +0000 | [diff] [blame] | 376 | for (const char *K : ValidKeys) { |
| 377 | if (Key.equals(K)) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 378 | return true; |
| 379 | } |
| 380 | return false; |
| 381 | } |
| 382 | |
| 383 | void Input::setError(const Twine &Message) { |
| 384 | this->setError(CurrentNode, Message); |
| 385 | } |
| 386 | |
Aaron Ballman | 0e63e53 | 2013-08-15 23:17:53 +0000 | [diff] [blame] | 387 | bool Input::canElideEmptySequence() { |
| 388 | return false; |
| 389 | } |
| 390 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 391 | //===----------------------------------------------------------------------===// |
| 392 | // Output |
| 393 | //===----------------------------------------------------------------------===// |
| 394 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 395 | Output::Output(raw_ostream &yout, void *context) |
| 396 | : IO(context), |
| 397 | Out(yout), |
| 398 | Column(0), |
| 399 | ColumnAtFlowStart(0), |
Alex Lorenz | b122508 | 2015-05-04 20:11:40 +0000 | [diff] [blame] | 400 | ColumnAtMapFlowStart(0), |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 401 | NeedBitValueComma(false), |
| 402 | NeedFlowSequenceComma(false), |
| 403 | EnumerationMatchFound(false), |
| 404 | NeedsNewLine(false) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | Output::~Output() { |
| 408 | } |
| 409 | |
Nick Kledzik | 4761c60 | 2013-11-21 00:20:10 +0000 | [diff] [blame] | 410 | bool Output::outputting() { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 411 | return true; |
| 412 | } |
| 413 | |
| 414 | void Output::beginMapping() { |
| 415 | StateStack.push_back(inMapFirstKey); |
| 416 | NeedsNewLine = true; |
| 417 | } |
| 418 | |
Nick Kledzik | 1e6033c | 2013-11-14 00:59:59 +0000 | [diff] [blame] | 419 | bool Output::mapTag(StringRef Tag, bool Use) { |
| 420 | if (Use) { |
| 421 | this->output(" "); |
| 422 | this->output(Tag); |
| 423 | } |
| 424 | return Use; |
| 425 | } |
| 426 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 427 | void Output::endMapping() { |
| 428 | StateStack.pop_back(); |
| 429 | } |
| 430 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 431 | bool Output::preflightKey(const char *Key, bool Required, bool SameAsDefault, |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 432 | bool &UseDefault, void *&) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 433 | UseDefault = false; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 434 | if (Required || !SameAsDefault) { |
Alex Lorenz | b122508 | 2015-05-04 20:11:40 +0000 | [diff] [blame] | 435 | auto State = StateStack.back(); |
| 436 | if (State == inFlowMapFirstKey || State == inFlowMapOtherKey) { |
| 437 | flowKey(Key); |
| 438 | } else { |
| 439 | this->newLineCheck(); |
| 440 | this->paddedKey(Key); |
| 441 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 442 | return true; |
| 443 | } |
| 444 | return false; |
| 445 | } |
| 446 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 447 | void Output::postflightKey(void *) { |
| 448 | if (StateStack.back() == inMapFirstKey) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 449 | StateStack.pop_back(); |
| 450 | StateStack.push_back(inMapOtherKey); |
Alex Lorenz | b122508 | 2015-05-04 20:11:40 +0000 | [diff] [blame] | 451 | } else if (StateStack.back() == inFlowMapFirstKey) { |
| 452 | StateStack.pop_back(); |
| 453 | StateStack.push_back(inFlowMapOtherKey); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
Alex Lorenz | b122508 | 2015-05-04 20:11:40 +0000 | [diff] [blame] | 457 | void Output::beginFlowMapping() { |
| 458 | StateStack.push_back(inFlowMapFirstKey); |
| 459 | this->newLineCheck(); |
| 460 | ColumnAtMapFlowStart = Column; |
| 461 | output("{ "); |
| 462 | } |
| 463 | |
| 464 | void Output::endFlowMapping() { |
| 465 | StateStack.pop_back(); |
| 466 | this->outputUpToEndOfLine(" }"); |
| 467 | } |
| 468 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 469 | void Output::beginDocuments() { |
| 470 | this->outputUpToEndOfLine("---"); |
| 471 | } |
| 472 | |
| 473 | bool Output::preflightDocument(unsigned index) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 474 | if (index > 0) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 475 | this->outputUpToEndOfLine("\n---"); |
| 476 | return true; |
| 477 | } |
| 478 | |
| 479 | void Output::postflightDocument() { |
| 480 | } |
| 481 | |
| 482 | void Output::endDocuments() { |
| 483 | output("\n...\n"); |
| 484 | } |
| 485 | |
| 486 | unsigned Output::beginSequence() { |
| 487 | StateStack.push_back(inSeq); |
| 488 | NeedsNewLine = true; |
| 489 | return 0; |
| 490 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 491 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 492 | void Output::endSequence() { |
| 493 | StateStack.pop_back(); |
| 494 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 495 | |
| 496 | bool Output::preflightElement(unsigned, void *&) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 497 | return true; |
| 498 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 499 | |
| 500 | void Output::postflightElement(void *) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | unsigned Output::beginFlowSequence() { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 504 | StateStack.push_back(inFlowSeq); |
Nick Kledzik | 11964f2 | 2013-01-04 19:32:00 +0000 | [diff] [blame] | 505 | this->newLineCheck(); |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 506 | ColumnAtFlowStart = Column; |
| 507 | output("[ "); |
| 508 | NeedFlowSequenceComma = false; |
| 509 | return 0; |
| 510 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 511 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 512 | void Output::endFlowSequence() { |
| 513 | StateStack.pop_back(); |
| 514 | this->outputUpToEndOfLine(" ]"); |
| 515 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 516 | |
| 517 | bool Output::preflightFlowElement(unsigned, void *&) { |
| 518 | if (NeedFlowSequenceComma) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 519 | output(", "); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 520 | if (Column > 70) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 521 | output("\n"); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 522 | for (int i = 0; i < ColumnAtFlowStart; ++i) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 523 | output(" "); |
| 524 | Column = ColumnAtFlowStart; |
| 525 | output(" "); |
| 526 | } |
| 527 | return true; |
| 528 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 529 | |
| 530 | void Output::postflightFlowElement(void *) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 531 | NeedFlowSequenceComma = true; |
| 532 | } |
| 533 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 534 | void Output::beginEnumScalar() { |
| 535 | EnumerationMatchFound = false; |
| 536 | } |
| 537 | |
| 538 | bool Output::matchEnumScalar(const char *Str, bool Match) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 539 | if (Match && !EnumerationMatchFound) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 540 | this->newLineCheck(); |
| 541 | this->outputUpToEndOfLine(Str); |
| 542 | EnumerationMatchFound = true; |
| 543 | } |
| 544 | return false; |
| 545 | } |
| 546 | |
Michael J. Spencer | 731cae3 | 2015-01-23 21:57:50 +0000 | [diff] [blame] | 547 | bool Output::matchEnumFallback() { |
| 548 | if (EnumerationMatchFound) |
| 549 | return false; |
| 550 | EnumerationMatchFound = true; |
| 551 | return true; |
| 552 | } |
| 553 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 554 | void Output::endEnumScalar() { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 555 | if (!EnumerationMatchFound) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 556 | llvm_unreachable("bad runtime enum value"); |
| 557 | } |
| 558 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 559 | bool Output::beginBitSetScalar(bool &DoClear) { |
| 560 | this->newLineCheck(); |
| 561 | output("[ "); |
| 562 | NeedBitValueComma = false; |
| 563 | DoClear = false; |
| 564 | return true; |
| 565 | } |
| 566 | |
| 567 | bool Output::bitSetMatch(const char *Str, bool Matches) { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 568 | if (Matches) { |
| 569 | if (NeedBitValueComma) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 570 | output(", "); |
| 571 | this->output(Str); |
| 572 | NeedBitValueComma = true; |
| 573 | } |
| 574 | return false; |
| 575 | } |
| 576 | |
| 577 | void Output::endBitSetScalar() { |
| 578 | this->outputUpToEndOfLine(" ]"); |
| 579 | } |
| 580 | |
David Majnemer | 7788033 | 2014-04-10 07:37:33 +0000 | [diff] [blame] | 581 | void Output::scalarString(StringRef &S, bool MustQuote) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 582 | this->newLineCheck(); |
Rui Ueyama | 106eded | 2013-09-11 04:00:08 +0000 | [diff] [blame] | 583 | if (S.empty()) { |
| 584 | // Print '' for the empty string because leaving the field empty is not |
| 585 | // allowed. |
| 586 | this->outputUpToEndOfLine("''"); |
| 587 | return; |
| 588 | } |
David Majnemer | 7788033 | 2014-04-10 07:37:33 +0000 | [diff] [blame] | 589 | if (!MustQuote) { |
| 590 | // Only quote if we must. |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 591 | this->outputUpToEndOfLine(S); |
| 592 | return; |
| 593 | } |
| 594 | unsigned i = 0; |
| 595 | unsigned j = 0; |
| 596 | unsigned End = S.size(); |
| 597 | output("'"); // Starting single quote. |
| 598 | const char *Base = S.data(); |
| 599 | while (j < End) { |
| 600 | // Escape a single quote by doubling it. |
| 601 | if (S[j] == '\'') { |
| 602 | output(StringRef(&Base[i], j - i + 1)); |
| 603 | output("'"); |
| 604 | i = j + 1; |
| 605 | } |
| 606 | ++j; |
| 607 | } |
| 608 | output(StringRef(&Base[i], j - i)); |
| 609 | this->outputUpToEndOfLine("'"); // Ending single quote. |
| 610 | } |
| 611 | |
| 612 | void Output::setError(const Twine &message) { |
| 613 | } |
| 614 | |
Aaron Ballman | 0e63e53 | 2013-08-15 23:17:53 +0000 | [diff] [blame] | 615 | bool Output::canElideEmptySequence() { |
| 616 | // Normally, with an optional key/value where the value is an empty sequence, |
| 617 | // the whole key/value can be not written. But, that produces wrong yaml |
| 618 | // if the key/value is the only thing in the map and the map is used in |
| 619 | // a sequence. This detects if the this sequence is the first key/value |
| 620 | // in map that itself is embedded in a sequnce. |
Rui Ueyama | 38dfffa | 2013-09-11 00:53:07 +0000 | [diff] [blame] | 621 | if (StateStack.size() < 2) |
Aaron Ballman | 0e63e53 | 2013-08-15 23:17:53 +0000 | [diff] [blame] | 622 | return true; |
Rui Ueyama | 38dfffa | 2013-09-11 00:53:07 +0000 | [diff] [blame] | 623 | if (StateStack.back() != inMapFirstKey) |
Aaron Ballman | 0e63e53 | 2013-08-15 23:17:53 +0000 | [diff] [blame] | 624 | return true; |
| 625 | return (StateStack[StateStack.size()-2] != inSeq); |
| 626 | } |
| 627 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 628 | void Output::output(StringRef s) { |
| 629 | Column += s.size(); |
| 630 | Out << s; |
| 631 | } |
| 632 | |
| 633 | void Output::outputUpToEndOfLine(StringRef s) { |
| 634 | this->output(s); |
Alex Lorenz | b122508 | 2015-05-04 20:11:40 +0000 | [diff] [blame] | 635 | if (StateStack.empty() || (StateStack.back() != inFlowSeq && |
| 636 | StateStack.back() != inFlowMapFirstKey && |
| 637 | StateStack.back() != inFlowMapOtherKey)) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 638 | NeedsNewLine = true; |
| 639 | } |
| 640 | |
| 641 | void Output::outputNewLine() { |
| 642 | Out << "\n"; |
| 643 | Column = 0; |
| 644 | } |
| 645 | |
| 646 | // if seq at top, indent as if map, then add "- " |
| 647 | // if seq in middle, use "- " if firstKey, else use " " |
| 648 | // |
| 649 | |
| 650 | void Output::newLineCheck() { |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 651 | if (!NeedsNewLine) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 652 | return; |
| 653 | NeedsNewLine = false; |
| 654 | |
| 655 | this->outputNewLine(); |
| 656 | |
| 657 | assert(StateStack.size() > 0); |
| 658 | unsigned Indent = StateStack.size() - 1; |
| 659 | bool OutputDash = false; |
| 660 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 661 | if (StateStack.back() == inSeq) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 662 | OutputDash = true; |
Alex Lorenz | 42e91fa | 2015-05-01 18:34:25 +0000 | [diff] [blame] | 663 | } else if ((StateStack.size() > 1) && ((StateStack.back() == inMapFirstKey) || |
Alex Lorenz | b122508 | 2015-05-04 20:11:40 +0000 | [diff] [blame] | 664 | (StateStack.back() == inFlowSeq) || |
| 665 | (StateStack.back() == inFlowMapFirstKey)) && |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 666 | (StateStack[StateStack.size() - 2] == inSeq)) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 667 | --Indent; |
| 668 | OutputDash = true; |
| 669 | } |
| 670 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 671 | for (unsigned i = 0; i < Indent; ++i) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 672 | output(" "); |
| 673 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 674 | if (OutputDash) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 675 | output("- "); |
| 676 | } |
| 677 | |
| 678 | } |
| 679 | |
| 680 | void Output::paddedKey(StringRef key) { |
| 681 | output(key); |
| 682 | output(":"); |
| 683 | const char *spaces = " "; |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 684 | if (key.size() < strlen(spaces)) |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 685 | output(&spaces[key.size()]); |
| 686 | else |
| 687 | output(" "); |
| 688 | } |
| 689 | |
Alex Lorenz | b122508 | 2015-05-04 20:11:40 +0000 | [diff] [blame] | 690 | void Output::flowKey(StringRef Key) { |
| 691 | if (StateStack.back() == inFlowMapOtherKey) |
| 692 | output(", "); |
| 693 | if (Column > 70) { |
| 694 | output("\n"); |
| 695 | for (int I = 0; I < ColumnAtMapFlowStart; ++I) |
| 696 | output(" "); |
| 697 | Column = ColumnAtMapFlowStart; |
| 698 | output(" "); |
| 699 | } |
| 700 | output(Key); |
| 701 | output(": "); |
| 702 | } |
| 703 | |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 704 | //===----------------------------------------------------------------------===// |
| 705 | // traits for built-in types |
| 706 | //===----------------------------------------------------------------------===// |
| 707 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 708 | void ScalarTraits<bool>::output(const bool &Val, void *, raw_ostream &Out) { |
| 709 | Out << (Val ? "true" : "false"); |
| 710 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 711 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 712 | StringRef ScalarTraits<bool>::input(StringRef Scalar, void *, bool &Val) { |
| 713 | if (Scalar.equals("true")) { |
| 714 | Val = true; |
| 715 | return StringRef(); |
| 716 | } else if (Scalar.equals("false")) { |
| 717 | Val = false; |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 718 | return StringRef(); |
| 719 | } |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 720 | return "invalid boolean"; |
| 721 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 722 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 723 | void ScalarTraits<StringRef>::output(const StringRef &Val, void *, |
| 724 | raw_ostream &Out) { |
| 725 | Out << Val; |
| 726 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 727 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 728 | StringRef ScalarTraits<StringRef>::input(StringRef Scalar, void *, |
| 729 | StringRef &Val) { |
| 730 | Val = Scalar; |
| 731 | return StringRef(); |
| 732 | } |
Alex Rosenberg | f298f16 | 2015-01-26 18:02:18 +0000 | [diff] [blame] | 733 | |
John Thompson | 48e018a | 2013-11-19 17:28:21 +0000 | [diff] [blame] | 734 | void ScalarTraits<std::string>::output(const std::string &Val, void *, |
| 735 | raw_ostream &Out) { |
| 736 | Out << Val; |
| 737 | } |
| 738 | |
| 739 | StringRef ScalarTraits<std::string>::input(StringRef Scalar, void *, |
| 740 | std::string &Val) { |
| 741 | Val = Scalar.str(); |
| 742 | return StringRef(); |
| 743 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 744 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 745 | void ScalarTraits<uint8_t>::output(const uint8_t &Val, void *, |
| 746 | raw_ostream &Out) { |
| 747 | // use temp uin32_t because ostream thinks uint8_t is a character |
| 748 | uint32_t Num = Val; |
| 749 | Out << Num; |
| 750 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 751 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 752 | StringRef ScalarTraits<uint8_t>::input(StringRef Scalar, void *, uint8_t &Val) { |
| 753 | unsigned long long n; |
| 754 | if (getAsUnsignedInteger(Scalar, 0, n)) |
| 755 | return "invalid number"; |
| 756 | if (n > 0xFF) |
| 757 | return "out of range number"; |
| 758 | Val = n; |
| 759 | return StringRef(); |
| 760 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 761 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 762 | void ScalarTraits<uint16_t>::output(const uint16_t &Val, void *, |
| 763 | raw_ostream &Out) { |
| 764 | Out << Val; |
| 765 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 766 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 767 | StringRef ScalarTraits<uint16_t>::input(StringRef Scalar, void *, |
| 768 | uint16_t &Val) { |
| 769 | unsigned long long n; |
| 770 | if (getAsUnsignedInteger(Scalar, 0, n)) |
| 771 | return "invalid number"; |
| 772 | if (n > 0xFFFF) |
| 773 | return "out of range number"; |
| 774 | Val = n; |
| 775 | return StringRef(); |
| 776 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 777 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 778 | void ScalarTraits<uint32_t>::output(const uint32_t &Val, void *, |
| 779 | raw_ostream &Out) { |
| 780 | Out << Val; |
| 781 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 782 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 783 | StringRef ScalarTraits<uint32_t>::input(StringRef Scalar, void *, |
| 784 | uint32_t &Val) { |
| 785 | unsigned long long n; |
| 786 | if (getAsUnsignedInteger(Scalar, 0, n)) |
| 787 | return "invalid number"; |
| 788 | if (n > 0xFFFFFFFFUL) |
| 789 | return "out of range number"; |
| 790 | Val = n; |
| 791 | return StringRef(); |
| 792 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 793 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 794 | void ScalarTraits<uint64_t>::output(const uint64_t &Val, void *, |
| 795 | raw_ostream &Out) { |
| 796 | Out << Val; |
| 797 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 798 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 799 | StringRef ScalarTraits<uint64_t>::input(StringRef Scalar, void *, |
| 800 | uint64_t &Val) { |
| 801 | unsigned long long N; |
| 802 | if (getAsUnsignedInteger(Scalar, 0, N)) |
| 803 | return "invalid number"; |
| 804 | Val = N; |
| 805 | return StringRef(); |
| 806 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 807 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 808 | void ScalarTraits<int8_t>::output(const int8_t &Val, void *, raw_ostream &Out) { |
| 809 | // use temp in32_t because ostream thinks int8_t is a character |
| 810 | int32_t Num = Val; |
| 811 | Out << Num; |
| 812 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 813 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 814 | StringRef ScalarTraits<int8_t>::input(StringRef Scalar, void *, int8_t &Val) { |
| 815 | long long N; |
| 816 | if (getAsSignedInteger(Scalar, 0, N)) |
| 817 | return "invalid number"; |
| 818 | if ((N > 127) || (N < -128)) |
| 819 | return "out of range number"; |
| 820 | Val = N; |
| 821 | return StringRef(); |
| 822 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 823 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 824 | void ScalarTraits<int16_t>::output(const int16_t &Val, void *, |
| 825 | raw_ostream &Out) { |
| 826 | Out << Val; |
| 827 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 828 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 829 | StringRef ScalarTraits<int16_t>::input(StringRef Scalar, void *, int16_t &Val) { |
| 830 | long long N; |
| 831 | if (getAsSignedInteger(Scalar, 0, N)) |
| 832 | return "invalid number"; |
| 833 | if ((N > INT16_MAX) || (N < INT16_MIN)) |
| 834 | return "out of range number"; |
| 835 | Val = N; |
| 836 | return StringRef(); |
| 837 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 838 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 839 | void ScalarTraits<int32_t>::output(const int32_t &Val, void *, |
| 840 | raw_ostream &Out) { |
| 841 | Out << Val; |
| 842 | } |
| 843 | |
| 844 | StringRef ScalarTraits<int32_t>::input(StringRef Scalar, void *, int32_t &Val) { |
| 845 | long long N; |
| 846 | if (getAsSignedInteger(Scalar, 0, N)) |
| 847 | return "invalid number"; |
| 848 | if ((N > INT32_MAX) || (N < INT32_MIN)) |
| 849 | return "out of range number"; |
| 850 | Val = N; |
| 851 | return StringRef(); |
| 852 | } |
| 853 | |
| 854 | void ScalarTraits<int64_t>::output(const int64_t &Val, void *, |
| 855 | raw_ostream &Out) { |
| 856 | Out << Val; |
| 857 | } |
| 858 | |
| 859 | StringRef ScalarTraits<int64_t>::input(StringRef Scalar, void *, int64_t &Val) { |
| 860 | long long N; |
| 861 | if (getAsSignedInteger(Scalar, 0, N)) |
| 862 | return "invalid number"; |
| 863 | Val = N; |
| 864 | return StringRef(); |
| 865 | } |
| 866 | |
| 867 | void ScalarTraits<double>::output(const double &Val, void *, raw_ostream &Out) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 868 | Out << format("%g", Val); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 869 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 870 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 871 | StringRef ScalarTraits<double>::input(StringRef Scalar, void *, double &Val) { |
| 872 | SmallString<32> buff(Scalar.begin(), Scalar.end()); |
| 873 | char *end; |
| 874 | Val = strtod(buff.c_str(), &end); |
| 875 | if (*end != '\0') |
| 876 | return "invalid floating point number"; |
| 877 | return StringRef(); |
| 878 | } |
| 879 | |
| 880 | void ScalarTraits<float>::output(const float &Val, void *, raw_ostream &Out) { |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 881 | Out << format("%g", Val); |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 882 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 883 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 884 | StringRef ScalarTraits<float>::input(StringRef Scalar, void *, float &Val) { |
| 885 | SmallString<32> buff(Scalar.begin(), Scalar.end()); |
| 886 | char *end; |
| 887 | Val = strtod(buff.c_str(), &end); |
| 888 | if (*end != '\0') |
| 889 | return "invalid floating point number"; |
| 890 | return StringRef(); |
| 891 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 892 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 893 | void ScalarTraits<Hex8>::output(const Hex8 &Val, void *, raw_ostream &Out) { |
| 894 | uint8_t Num = Val; |
| 895 | Out << format("0x%02X", Num); |
| 896 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 897 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 898 | StringRef ScalarTraits<Hex8>::input(StringRef Scalar, void *, Hex8 &Val) { |
| 899 | unsigned long long n; |
| 900 | if (getAsUnsignedInteger(Scalar, 0, n)) |
| 901 | return "invalid hex8 number"; |
| 902 | if (n > 0xFF) |
| 903 | return "out of range hex8 number"; |
| 904 | Val = n; |
| 905 | return StringRef(); |
| 906 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 907 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 908 | void ScalarTraits<Hex16>::output(const Hex16 &Val, void *, raw_ostream &Out) { |
| 909 | uint16_t Num = Val; |
| 910 | Out << format("0x%04X", Num); |
| 911 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 912 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 913 | StringRef ScalarTraits<Hex16>::input(StringRef Scalar, void *, Hex16 &Val) { |
| 914 | unsigned long long n; |
| 915 | if (getAsUnsignedInteger(Scalar, 0, n)) |
| 916 | return "invalid hex16 number"; |
| 917 | if (n > 0xFFFF) |
| 918 | return "out of range hex16 number"; |
| 919 | Val = n; |
| 920 | return StringRef(); |
| 921 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 922 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 923 | void ScalarTraits<Hex32>::output(const Hex32 &Val, void *, raw_ostream &Out) { |
| 924 | uint32_t Num = Val; |
| 925 | Out << format("0x%08X", Num); |
| 926 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 927 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 928 | StringRef ScalarTraits<Hex32>::input(StringRef Scalar, void *, Hex32 &Val) { |
| 929 | unsigned long long n; |
| 930 | if (getAsUnsignedInteger(Scalar, 0, n)) |
| 931 | return "invalid hex32 number"; |
| 932 | if (n > 0xFFFFFFFFUL) |
| 933 | return "out of range hex32 number"; |
| 934 | Val = n; |
| 935 | return StringRef(); |
| 936 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 937 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 938 | void ScalarTraits<Hex64>::output(const Hex64 &Val, void *, raw_ostream &Out) { |
| 939 | uint64_t Num = Val; |
| 940 | Out << format("0x%016llX", Num); |
| 941 | } |
Nick Kledzik | f60a927 | 2012-12-12 20:46:15 +0000 | [diff] [blame] | 942 | |
Benjamin Kramer | 36b0f12 | 2012-12-12 22:40:02 +0000 | [diff] [blame] | 943 | StringRef ScalarTraits<Hex64>::input(StringRef Scalar, void *, Hex64 &Val) { |
| 944 | unsigned long long Num; |
| 945 | if (getAsUnsignedInteger(Scalar, 0, Num)) |
| 946 | return "invalid hex64 number"; |
| 947 | Val = Num; |
| 948 | return StringRef(); |
| 949 | } |