diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp --- a/llvm/lib/Support/YAMLTraits.cpp +++ b/llvm/lib/Support/YAMLTraits.cpp @@ -397,17 +397,23 @@ std::unique_ptr Input::createHNodes(Node *N) { SmallString<128> StringStorage; - if (ScalarNode *SN = dyn_cast(N)) { + switch (N->getType()) { + case Node::NK_Scalar: { + ScalarNode *SN = dyn_cast(N); StringRef KeyStr = SN->getValue(StringStorage); if (!StringStorage.empty()) { // Copy string to permanent storage KeyStr = StringStorage.str().copy(StringAllocator); } return std::make_unique(N, KeyStr); - } else if (BlockScalarNode *BSN = dyn_cast(N)) { + } + case Node::NK_BlockScalar: { + BlockScalarNode *BSN = dyn_cast(N); StringRef ValueCopy = BSN->getValue().copy(StringAllocator); return std::make_unique(N, ValueCopy); - } else if (SequenceNode *SQ = dyn_cast(N)) { + } + case Node::NK_Sequence: { + SequenceNode *SQ = dyn_cast(N); auto SQHNode = std::make_unique(N); for (Node &SN : *SQ) { auto Entry = createHNodes(&SN); @@ -416,7 +422,9 @@ SQHNode->Entries.push_back(std::move(Entry)); } return std::move(SQHNode); - } else if (MappingNode *Map = dyn_cast(N)) { + } + case Node::NK_Mapping: { + MappingNode *Map = dyn_cast(N); auto mapHNode = std::make_unique(N); for (KeyValueNode &KVN : *Map) { Node *KeyNode = KVN.getKey(); @@ -447,9 +455,10 @@ std::make_pair(std::move(ValueHNode), KeyNode->getSourceRange()); } return std::move(mapHNode); - } else if (isa(N)) { + } + case Node::NK_Null: return std::make_unique(N); - } else { + default: setError(N, "unknown node kind"); return nullptr; }