File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,13 @@ inline T *makePointerFromOptional(Optional<T *> value) {
41
41
// In addition to the concrete type names, BasicReader is expected to
42
42
// implement these methods:
43
43
//
44
+ // template <class EnumType>
45
+ // void writeEnum(T value);
46
+ //
47
+ // Reads an enum value from the current property. EnumType will always
48
+ // be an enum type. Only necessary if the BasicReader doesn't provide
49
+ // type-specific readers for all the enum types.
50
+ //
44
51
// template <class ValueType>
45
52
// Optional<ValueType> writeOptional();
46
53
//
@@ -127,6 +134,11 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
127
134
return asImpl ();
128
135
}
129
136
137
+ template <class T >
138
+ T readEnum () {
139
+ return T (asImpl ().readUInt32 ());
140
+ }
141
+
130
142
// Implement object reading by forwarding to this, collapsing the
131
143
// structure into a single data stream.
132
144
Impl &readObject () { return asImpl (); }
Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
42
42
// In addition to the concrete property types, BasicWriter is expected
43
43
// to implement these methods:
44
44
//
45
+ // template <class EnumType>
46
+ // void writeEnum(T value);
47
+ //
48
+ // Writes an enum value as the current property. EnumType will always
49
+ // be an enum type. Only necessary if the BasicWriter doesn't provide
50
+ // type-specific writers for all the enum types.
51
+ //
45
52
// template <class ValueType>
46
53
// void writeOptional(Optional<ValueType> value);
47
54
//
@@ -126,6 +133,11 @@ class DataStreamBasicWriter : public BasicWriterBase<Impl> {
126
133
// structure into a single data stream.
127
134
Impl &writeObject () { return asImpl (); }
128
135
136
+ template <class T >
137
+ void writeEnum (T value) {
138
+ asImpl ().writeUInt32 (uint32_t (value));
139
+ }
140
+
129
141
template <class T >
130
142
void writeArray (llvm::ArrayRef<T> array) {
131
143
asImpl ().writeUInt32 (array.size ());
Original file line number Diff line number Diff line change @@ -757,10 +757,10 @@ ASTPropsEmitter::emitBasicReaderWriterTemplate(const ReaderWriterInfo &info) {
757
757
} else if (type.isEnum ()) {
758
758
enterMethod (" value" );
759
759
if (info.IsReader )
760
- Out << " return " << type. getCXXTypeName ()
761
- << " (asImpl().readUInt32() );\n " ;
760
+ Out << " return asImpl().template readEnum< "
761
+ << type. getCXXTypeName () << " >( );\n " ;
762
762
else
763
- Out << " asImpl().writeUInt32(uint32_t( value) );\n " ;
763
+ Out << " asImpl().writeEnum( value);\n " ;
764
764
exitMethod ();
765
765
766
766
} else if (PropertyType superclass = type.getSuperclassType ()) {
You can’t perform that action at this time.
0 commit comments