Fix how YAML I/O detects flow sequences.
Update test case to verify flow sequence is written as a flow sequence. llvm-svn: 171514
This commit is contained in:
parent
f412e7501a
commit
11964f2a8f
|
@ -276,20 +276,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// Test if SequenceTraits<T> is defined on type T
|
// Test if SequenceTraits<T> is defined on type T
|
||||||
// and SequenceTraits<T>::flow is *not* defined.
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct has_SequenceTraits : public llvm::integral_constant<bool,
|
struct has_SequenceTraits : public llvm::integral_constant<bool,
|
||||||
has_SequenceMethodTraits<T>::value
|
has_SequenceMethodTraits<T>::value > { };
|
||||||
&& !has_FlowTraits<T>::value > { };
|
|
||||||
|
|
||||||
|
|
||||||
// Test if SequenceTraits<T> is defined on type T
|
|
||||||
// and SequenceTraits<T>::flow is defined.
|
|
||||||
template<typename T>
|
|
||||||
struct has_FlowSequenceTraits : public llvm::integral_constant<bool,
|
|
||||||
has_SequenceMethodTraits<T>::value
|
|
||||||
&& has_FlowTraits<T>::value > { };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Test if DocumentListTraits<T> is defined on type T
|
// Test if DocumentListTraits<T> is defined on type T
|
||||||
|
@ -318,7 +307,6 @@ struct missingTraits : public llvm::integral_constant<bool,
|
||||||
&& !has_ScalarTraits<T>::value
|
&& !has_ScalarTraits<T>::value
|
||||||
&& !has_MappingTraits<T>::value
|
&& !has_MappingTraits<T>::value
|
||||||
&& !has_SequenceTraits<T>::value
|
&& !has_SequenceTraits<T>::value
|
||||||
&& !has_FlowSequenceTraits<T>::value
|
|
||||||
&& !has_DocumentListTraits<T>::value > {};
|
&& !has_DocumentListTraits<T>::value > {};
|
||||||
|
|
||||||
|
|
||||||
|
@ -510,35 +498,33 @@ yamlize(IO &io, T &Val, bool) {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename llvm::enable_if_c<has_SequenceTraits<T>::value,void>::type
|
typename llvm::enable_if_c<has_SequenceTraits<T>::value,void>::type
|
||||||
yamlize(IO &io, T &Seq, bool) {
|
yamlize(IO &io, T &Seq, bool) {
|
||||||
unsigned incount = io.beginSequence();
|
if ( has_FlowTraits< SequenceTraits<T> >::value ) {
|
||||||
unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incount;
|
unsigned incnt = io.beginFlowSequence();
|
||||||
for(unsigned i=0; i < count; ++i) {
|
unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
|
||||||
void *SaveInfo;
|
for(unsigned i=0; i < count; ++i) {
|
||||||
if ( io.preflightElement(i, SaveInfo) ) {
|
void *SaveInfo;
|
||||||
yamlize(io, SequenceTraits<T>::element(io, Seq, i), true);
|
if ( io.preflightFlowElement(i, SaveInfo) ) {
|
||||||
io.postflightElement(SaveInfo);
|
yamlize(io, SequenceTraits<T>::element(io, Seq, i), true);
|
||||||
|
io.postflightFlowElement(SaveInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
io.endFlowSequence();
|
||||||
}
|
}
|
||||||
io.endSequence();
|
else {
|
||||||
}
|
unsigned incnt = io.beginSequence();
|
||||||
|
unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
|
||||||
template<typename T>
|
for(unsigned i=0; i < count; ++i) {
|
||||||
typename llvm::enable_if_c<has_FlowSequenceTraits<T>::value,void>::type
|
void *SaveInfo;
|
||||||
yamlize(IO &io, T &Seq, bool) {
|
if ( io.preflightElement(i, SaveInfo) ) {
|
||||||
unsigned incount = io.beginFlowSequence();
|
yamlize(io, SequenceTraits<T>::element(io, Seq, i), true);
|
||||||
unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incount;
|
io.postflightElement(SaveInfo);
|
||||||
for(unsigned i=0; i < count; ++i) {
|
}
|
||||||
void *SaveInfo;
|
|
||||||
if ( io.preflightFlowElement(i, SaveInfo) ) {
|
|
||||||
yamlize(io, SequenceTraits<T>::element(io, Seq, i), true);
|
|
||||||
io.postflightFlowElement(SaveInfo);
|
|
||||||
}
|
}
|
||||||
|
io.endSequence();
|
||||||
}
|
}
|
||||||
io.endFlowSequence();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ScalarTraits<bool> {
|
struct ScalarTraits<bool> {
|
||||||
static void output(const bool &, void*, llvm::raw_ostream &);
|
static void output(const bool &, void*, llvm::raw_ostream &);
|
||||||
|
|
|
@ -411,8 +411,8 @@ void Output::postflightElement(void *) {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Output::beginFlowSequence() {
|
unsigned Output::beginFlowSequence() {
|
||||||
this->newLineCheck();
|
|
||||||
StateStack.push_back(inFlowSeq);
|
StateStack.push_back(inFlowSeq);
|
||||||
|
this->newLineCheck();
|
||||||
ColumnAtFlowStart = Column;
|
ColumnAtFlowStart = Column;
|
||||||
output("[ ");
|
output("[ ");
|
||||||
NeedFlowSequenceComma = false;
|
NeedFlowSequenceComma = false;
|
||||||
|
|
|
@ -602,6 +602,12 @@ TEST(YAMLIO, TestReadWriteMyFlowSequence) {
|
||||||
llvm::raw_string_ostream ostr(intermediate);
|
llvm::raw_string_ostream ostr(intermediate);
|
||||||
Output yout(ostr);
|
Output yout(ostr);
|
||||||
yout << map;
|
yout << map;
|
||||||
|
|
||||||
|
// Verify sequences were written in flow style
|
||||||
|
ostr.flush();
|
||||||
|
llvm::StringRef flowOut(intermediate);
|
||||||
|
EXPECT_NE(llvm::StringRef::npos, flowOut.find("one, two"));
|
||||||
|
EXPECT_NE(llvm::StringRef::npos, flowOut.find("10, -30, 1024"));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -632,7 +638,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint32_t, TotalSeconds)
|
||||||
|
|
||||||
typedef std::vector<TotalSeconds> SecondsSequence;
|
typedef std::vector<TotalSeconds> SecondsSequence;
|
||||||
|
|
||||||
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TotalSeconds)
|
LLVM_YAML_IS_SEQUENCE_VECTOR(TotalSeconds)
|
||||||
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
@ -745,7 +751,7 @@ struct KindAndFlags {
|
||||||
|
|
||||||
typedef std::vector<KindAndFlags> KindAndFlagsSequence;
|
typedef std::vector<KindAndFlags> KindAndFlagsSequence;
|
||||||
|
|
||||||
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(KindAndFlags)
|
LLVM_YAML_IS_SEQUENCE_VECTOR(KindAndFlags)
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace yaml {
|
namespace yaml {
|
||||||
|
|
Loading…
Reference in New Issue