From 87dd2ab000000a0ee6c643293caf105710327c8b Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 4 Jan 2017 03:51:36 +0000 Subject: Support: Add YAML I/O support for custom mappings. This will be used to YAMLify parts of the module summary. Differential Revision: https://reviews.llvm.org/D28014 llvm-svn: 290935 --- llvm/lib/Support/YAMLTraits.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Support/YAMLTraits.cpp') diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp index 99d2070cb6e..51c016b1d55 100644 --- a/llvm/lib/Support/YAMLTraits.cpp +++ b/llvm/lib/Support/YAMLTraits.cpp @@ -118,6 +118,18 @@ void Input::beginMapping() { } } +std::vector Input::keys() { + MapHNode *MN = dyn_cast(CurrentNode); + std::vector Ret; + if (!MN) { + setError(CurrentNode, "not a mapping"); + return Ret; + } + for (auto &P : MN->Mapping) + Ret.push_back(P.first()); + return Ret; +} + bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault, void *&SaveInfo) { UseDefault = false; @@ -374,8 +386,8 @@ std::unique_ptr Input::createHNodes(Node *N) { } bool Input::MapHNode::isValidKey(StringRef Key) { - for (const char *K : ValidKeys) { - if (Key.equals(K)) + for (std::string &K : ValidKeys) { + if (Key == K) return true; } return false; @@ -451,6 +463,10 @@ void Output::endMapping() { StateStack.pop_back(); } +std::vector Output::keys() { + report_fatal_error("invalid call"); +} + bool Output::preflightKey(const char *Key, bool Required, bool SameAsDefault, bool &UseDefault, void *&) { UseDefault = false; -- cgit v1.2.3