[PATCH] D24479: [YAML] Add basic support for class hierarchies

kledzik@apple.com via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 16:13:19 PDT 2016


kledzik added inline comments.


> YAMLTraits.cpp:429
> +bool Output::mapTag(StringRef Tag, std::function<bool()> Use, bool Default) {
> +  return mapTag(Tag, Use());
> +}

I don't this is correct.  If then output case, if the lambda returns false, that means the object being outputted is not of this tag type, and therefore mapTag() should return false.

> YAMLIOTest.cpp:1608-1619
> +  static void mapping(IO &io, DoubleBase *&d) {
> +    if (io.mapTag("!decimal", [&]() { return d->kind == DoubleBase::decimal; },
> +                  true)) {
> +      if (!io.outputting())
> +        d = new DoubleDecimal;
> +      mappingDecimal(io, static_cast<DoubleDecimal *>(d));
> +    } else if (io.mapTag("!fraction",

Without making any changes to mapTag(),  you could implement this today as below.  Basically, in the output case, you switch off the dynamic type.  Of the input side, you switch off the tag.

static void mapping(IO &io, DoubleBase *&d) {

  if (io.outputting()) {
    switch (d->kind) {
    case DoubleBase::decimal:
      if (io.mapTag("!decimal", true) 
          mappingDecimal(io, static_cast<DoubleDecimal *>(d));
      break;
   case DoubleBase:: fraction:
      if (io.mapTag("!fraction", true) 
          mappingDecimal(io, static_cast<DoubleFraction *>(d));
      break;
  } else {
      if (io.mapTag("!decimal", true) {
        d = new DoubleDecimal;
        mappingDecimal(io, static_cast<DoubleDecimal *>(d));
      } else  if (io.mapTag("! fraction", true) {
        d = new DoubleFraction;
        mappingDecimal(io, static_cast<DoubleFraction *>(d));
    }

}

https://reviews.llvm.org/D24479





More information about the llvm-commits mailing list