[all-commits] [llvm/llvm-project] 31a575: [JSON] Add ObjectMapper::mapOptional to validate o...

Sam McCall via All-commits all-commits at lists.llvm.org
Mon Oct 12 03:58:57 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 31a575bbc0fc925c29bcd6fc49b5a100ad22ae63
      https://github.com/llvm/llvm-project/commit/31a575bbc0fc925c29bcd6fc49b5a100ad22ae63
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2020-10-12 (Mon, 12 Oct 2020)

  Changed paths:
    M llvm/include/llvm/Support/JSON.h
    M llvm/unittests/Support/JSONTest.cpp

  Log Message:
  -----------
  [JSON] Add ObjectMapper::mapOptional to validate optional data.

Currently the idiom for mapping optional fields is:
  ObjectMapper O(Val, P);
  if (!O.map("required1", Out.R1) || !O.map("required2", Out.R2))
    return false;
  O.map("optional1", Out.O1); // ignore result
  return true;

If `optional1` is present but malformed, then we won't detect/report
that error. We may even leave `Out` in an incomplete state while returning true.
Instead, we'd often prefer to ignore `optional1` if it is absent, but otherwise
behave just like map().

Differential Revision: https://reviews.llvm.org/D89128




More information about the All-commits mailing list