Skip to content

Commit 90719e7

Browse files
committed
Forward {read,write}SomeEnumType to {read,write}Enum instead of
directly to {read,write}UInt32. This will be useful for textual formats. NFC.
1 parent 5ccdd58 commit 90719e7

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

clang/include/clang/AST/AbstractBasicReader.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ inline T *makePointerFromOptional(Optional<T *> value) {
4141
// In addition to the concrete type names, BasicReader is expected to
4242
// implement these methods:
4343
//
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+
//
4451
// template <class ValueType>
4552
// Optional<ValueType> writeOptional();
4653
//
@@ -127,6 +134,11 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
127134
return asImpl();
128135
}
129136

137+
template <class T>
138+
T readEnum() {
139+
return T(asImpl().readUInt32());
140+
}
141+
130142
// Implement object reading by forwarding to this, collapsing the
131143
// structure into a single data stream.
132144
Impl &readObject() { return asImpl(); }

clang/include/clang/AST/AbstractBasicWriter.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ inline llvm::Optional<T*> makeOptionalFromPointer(T *value) {
4242
// In addition to the concrete property types, BasicWriter is expected
4343
// to implement these methods:
4444
//
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+
//
4552
// template <class ValueType>
4653
// void writeOptional(Optional<ValueType> value);
4754
//
@@ -126,6 +133,11 @@ class DataStreamBasicWriter : public BasicWriterBase<Impl> {
126133
// structure into a single data stream.
127134
Impl &writeObject() { return asImpl(); }
128135

136+
template <class T>
137+
void writeEnum(T value) {
138+
asImpl().writeUInt32(uint32_t(value));
139+
}
140+
129141
template <class T>
130142
void writeArray(llvm::ArrayRef<T> array) {
131143
asImpl().writeUInt32(array.size());

clang/utils/TableGen/ClangASTPropertiesEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,10 @@ ASTPropsEmitter::emitBasicReaderWriterTemplate(const ReaderWriterInfo &info) {
757757
} else if (type.isEnum()) {
758758
enterMethod("value");
759759
if (info.IsReader)
760-
Out << " return " << type.getCXXTypeName()
761-
<< "(asImpl().readUInt32());\n";
760+
Out << " return asImpl().template readEnum<"
761+
<< type.getCXXTypeName() << ">();\n";
762762
else
763-
Out << " asImpl().writeUInt32(uint32_t(value));\n";
763+
Out << " asImpl().writeEnum(value);\n";
764764
exitMethod();
765765

766766
} else if (PropertyType superclass = type.getSuperclassType()) {

0 commit comments

Comments
 (0)