forked from OSchip/llvm-project
Forward {read,write}SomeEnumType to {read,write}Enum instead of
directly to {read,write}UInt32. This will be useful for textual formats. NFC.
This commit is contained in:
parent
da74c4d2d8
commit
b699fe8b95
|
@ -41,6 +41,13 @@ inline T *makePointerFromOptional(Optional<T *> value) {
|
|||
// In addition to the concrete type names, BasicReader is expected to
|
||||
// implement these methods:
|
||||
//
|
||||
// template <class EnumType>
|
||||
// void writeEnum(T value);
|
||||
//
|
||||
// Reads an enum value from the current property. EnumType will always
|
||||
// be an enum type. Only necessary if the BasicReader doesn't provide
|
||||
// type-specific readers for all the enum types.
|
||||
//
|
||||
// template <class ValueType>
|
||||
// Optional<ValueType> writeOptional();
|
||||
//
|
||||
|
@ -127,6 +134,11 @@ public:
|
|||
return asImpl();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T readEnum() {
|
||||
return T(asImpl().readUInt32());
|
||||
}
|
||||
|
||||
// Implement object reading by forwarding to this, collapsing the
|
||||
// structure into a single data stream.
|
||||
Impl &readObject() { return asImpl(); }
|
||||
|
|
|
@ -42,6 +42,13 @@ inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
|
|||
// In addition to the concrete property types, BasicWriter is expected
|
||||
// to implement these methods:
|
||||
//
|
||||
// template <class EnumType>
|
||||
// void writeEnum(T value);
|
||||
//
|
||||
// Writes an enum value as the current property. EnumType will always
|
||||
// be an enum type. Only necessary if the BasicWriter doesn't provide
|
||||
// type-specific writers for all the enum types.
|
||||
//
|
||||
// template <class ValueType>
|
||||
// void writeOptional(Optional<ValueType> value);
|
||||
//
|
||||
|
@ -126,6 +133,11 @@ public:
|
|||
// structure into a single data stream.
|
||||
Impl &writeObject() { return asImpl(); }
|
||||
|
||||
template <class T>
|
||||
void writeEnum(T value) {
|
||||
asImpl().writeUInt32(uint32_t(value));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void writeArray(llvm::ArrayRef<T> array) {
|
||||
asImpl().writeUInt32(array.size());
|
||||
|
|
|
@ -757,10 +757,10 @@ ASTPropsEmitter::emitBasicReaderWriterTemplate(const ReaderWriterInfo &info) {
|
|||
} else if (type.isEnum()) {
|
||||
enterMethod("value");
|
||||
if (info.IsReader)
|
||||
Out << " return " << type.getCXXTypeName()
|
||||
<< "(asImpl().readUInt32());\n";
|
||||
Out << " return asImpl().template readEnum<"
|
||||
<< type.getCXXTypeName() << ">();\n";
|
||||
else
|
||||
Out << " asImpl().writeUInt32(uint32_t(value));\n";
|
||||
Out << " asImpl().writeEnum(value);\n";
|
||||
exitMethod();
|
||||
|
||||
} else if (PropertyType superclass = type.getSuperclassType()) {
|
||||
|
|
Loading…
Reference in New Issue