This is an archive of the discontinued LLVM Phabricator instance.

[YAML] Add basic support for class hierarchies
AbandonedPublic

Authored by anemet on Sep 12 2016, 3:55 PM.

Details

Reviewers
kledzik
hfinkel
Summary

Looks like that with some minimal generalization of mapTag, we can
support inheritance in YAML I/O. In the new testcase I modified the
previous tagging example to actually store the underlying implementation
(decimal vs. fraction) in the YAML output.

I am thinking of using this pattern to produce the YAML output for
optimization remarks (see, https://reviews.llvm.org/D19678#419445). The
relevant part of the optimization remark hierarchy starts at
DiagnosticInfoOptimizationBase
(http://llvm.org/doxygen/classllvm_1_1DiagnosticInfoOptimizationBase.html)

Diff Detail

Event Timeline

anemet updated this revision to Diff 71071.Sep 12 2016, 3:55 PM
anemet retitled this revision from to [YAML] Add basic support for class hierarchies.
anemet updated this object.
anemet added reviewers: kledzik, hfinkel.
anemet added a subscriber: llvm-commits.
fhahn added a subscriber: fhahn.Sep 13 2016, 3:52 AM
kledzik added inline comments.Sep 30 2016, 4:13 PM
lib/Support/YAMLTraits.cpp
429

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.

unittests/Support/YAMLIOTest.cpp
1608–1619

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));
  }

}

anemet abandoned this revision.Jan 3 2017, 9:32 AM

Talking to Nick in person a while ago, he was not fond of the use of lambda in this approach. I am abandoning this for now.