From 541b1a74941ace46213f8f8e2442230f8e0730da Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 7 Jan 2018 17:41:24 -0800 Subject: [PATCH] Fix MessagePackReader for Position/Range Go out for dinner --- src/position.cc | 50 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/position.cc b/src/position.cc index eb342a4b..8f506857 100644 --- a/src/position.cc +++ b/src/position.cc @@ -1,4 +1,5 @@ #include "position.h" +#include "serializers/msgpack.h" namespace { // Skips until the character immediately following |skip_after|. @@ -143,16 +144,22 @@ bool Range::operator<(const Range& that) const { // Position void Reflect(Reader& visitor, Position& value) { - if (!visitor.IsString()) - value = Position(); - else if (visitor.Format() == SerializeFormat::Json) { + if (visitor.Format() == SerializeFormat::Json) { std::string s = visitor.GetString(); value = Position(s.c_str()); } else { - REFLECT_MEMBER_START(2); - Reflect(visitor, value.line); - Reflect(visitor, value.column); - REFLECT_MEMBER_END(); + int i = 0; + // FIXME + static_cast(visitor).IterArray([&](Reader& entry) { + switch (i++) { + case 0: + Reflect(entry, value.line); + break; + case 1: + Reflect(entry, value.column); + break; + } + }); } } void Reflect(Writer& visitor, Position& value) { @@ -169,18 +176,29 @@ void Reflect(Writer& visitor, Position& value) { // Range void Reflect(Reader& visitor, Range& value) { - if (!visitor.IsString()) - value = Range(); - else if (visitor.Format() == SerializeFormat::Json) { + if (visitor.Format() == SerializeFormat::Json) { std::string s = visitor.GetString(); value = Range(s.c_str()); } else { - REFLECT_MEMBER_START(4); - Reflect(visitor, value.start.line); - Reflect(visitor, value.start.column); - Reflect(visitor, value.end.line); - Reflect(visitor, value.end.column); - REFLECT_MEMBER_END(); + int i = 0; + // FIXME + static_cast(visitor).IterArray([&](Reader& entry) { + switch (i++) { + case 0: + Reflect(entry, value.start.line); + break; + case 1: + Reflect(entry, value.start.column); + break; + case 2: + Reflect(entry, value.end.line); + break; + case 3: + Reflect(entry, value.end.column); + break; + } + i++; + }); } } void Reflect(Writer& visitor, Range& value) {