mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
Restore the separate enum declaration node
This commit is contained in:
committed by
Pietro Fezzardi
parent
42a045a2b5
commit
1609bbe745
@@ -5,6 +5,7 @@
|
||||
//
|
||||
|
||||
#include "revng/Clift/Clift.h"
|
||||
#include "revng/Clift/CliftTypes.h"
|
||||
#include "revng/PTML/CDoxygenEmitter.h"
|
||||
#include "revng/PTML/CTokenEmitter.h"
|
||||
#include "revng/Support/CDataModel.h"
|
||||
@@ -119,5 +120,5 @@ public:
|
||||
///
|
||||
/// This is true for `struct`s and `union`s. False for everything else.
|
||||
inline bool isSeparateDeclarationAllowed(clift::DefinedType Type) {
|
||||
return mlir::isa<clift::ClassType>(Type);
|
||||
return mlir::isa<clift::ClassType>(Type) or mlir::isa<clift::EnumType>(Type);
|
||||
}
|
||||
|
||||
@@ -107,9 +107,6 @@ void TypeDefinitionEmitter::emitTypeDeclaration(clift::DefinedType Type) {
|
||||
} else if (auto Typedef = mlir::dyn_cast<clift::TypedefType>(Type)) {
|
||||
emitTypedefDefinition(Typedef);
|
||||
|
||||
} else if (auto Enum = mlir::dyn_cast<clift::EnumType>(Type)) {
|
||||
emitEnumDefinition(Enum);
|
||||
|
||||
} else if (auto Function = mlir::dyn_cast<clift::FunctionType>(Type)) {
|
||||
emitFunctionTypedef(Function);
|
||||
|
||||
@@ -327,9 +324,6 @@ void TypeDefinitionEmitter::emitEnumDefinition(clift::EnumType Enum) {
|
||||
|
||||
Tokens.emitPunctuator(ptml::CTokenEmitter::Punctuator::Semicolon);
|
||||
Tokens.emitNewline();
|
||||
|
||||
// Allow using `MyEnum` instead of `enum MyEnum`.
|
||||
emitDeclarationTypedef(Enum);
|
||||
}
|
||||
|
||||
void TypeDefinitionEmitter::emitTypeDefinition(clift::DefinedType Type) {
|
||||
@@ -337,6 +331,10 @@ void TypeDefinitionEmitter::emitTypeDefinition(clift::DefinedType Type) {
|
||||
emitClassDefinition(Class);
|
||||
return;
|
||||
|
||||
} else if (auto Enum = mlir::dyn_cast<clift::EnumType>(Type)) {
|
||||
emitEnumDefinition(Enum);
|
||||
return;
|
||||
|
||||
} else if (not isSeparateDeclarationAllowed(Type)) {
|
||||
emitTypeDeclaration(Type);
|
||||
Tokens.emitNewline();
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "revng/CliftImportModel/ImportModel.h"
|
||||
#include "revng/ImportFromC/ImportFromCAnalysis.h"
|
||||
#include "revng/Model/Binary.h"
|
||||
#include "revng/Model/EnumDefinition.h"
|
||||
#include "revng/Model/VerifyHelper.h"
|
||||
#include "revng/PTML/CTokenEmitter.h"
|
||||
#include "revng/Pipeline/Context.h"
|
||||
@@ -80,7 +81,8 @@ static std::optional<std::string> findHeaderFile(const std::string &File) {
|
||||
|
||||
static bool isSeparateDeclarationAllowed(const model::TypeDefinition &T) {
|
||||
return llvm::isa<model::StructDefinition>(&T)
|
||||
or llvm::isa<model::UnionDefinition>(&T);
|
||||
or llvm::isa<model::UnionDefinition>(&T)
|
||||
or llvm::isa<model::EnumDefinition>(&T);
|
||||
}
|
||||
|
||||
static std::pair<std::unique_ptr<mlir::MLIRContext>,
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
|
||||
# CHECK: typedef _ABI(raw_x86_64) void rawfunction_3008(generic64_t, generic64_t, generic64_t, generic64_t, generic64_t, generic64_t);
|
||||
|
||||
# CHECK: typedef enum _PACKED prefix_enum_9 prefix_enum_9;
|
||||
|
||||
# CHECK: enum _ENUM_UNDERLYING(int64_t) _PACKED prefix_enum_9 {
|
||||
# CHECK: prefix_enum_9_none = 0x0U,
|
||||
# CHECK: prefix_enum_9_positive = 0x1U,
|
||||
# CHECK: prefix_enum_9_max_held_value = 0xFFFFFFFFU,
|
||||
# CHECK: };
|
||||
# CHECK: typedef enum _PACKED prefix_enum_9 prefix_enum_9;
|
||||
|
||||
# CHECK: _ABI(SystemV_x86_64) void fn(int32_t b, generic64_t c, uint16_t d);
|
||||
# CHECK: _ABI(raw_x86_64) void fn2(generic64_t register_rcx _REG(rcx_x86_64), generic64_t register_rdx _REG(rdx_x86_64), generic64_t register_rsi _REG(rsi_x86_64), generic64_t register_rdi _REG(rdi_x86_64), generic64_t register_r8 _REG(r8_x86_64), generic64_t register_r9 _REG(r9_x86_64));
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
!uint64_t = !clift.int<unsigned 8>
|
||||
|
||||
// CHECK: typedef enum _PACKED my_commented_enum my_commented_enum;
|
||||
|
||||
// CHECK: /// Take a look at struct and function comment tests for more "meat".
|
||||
// CHECK: ///
|
||||
// CHECK: /// This one is just to ensure enum-attached comments don't
|
||||
@@ -22,7 +24,6 @@
|
||||
// CHECK: /// And this one is too big for its own good!
|
||||
// CHECK: enum_entry_my_commented_enum_18446744073709551615 = 0xFFFFFFFFFFFFFFFFU,
|
||||
// CHECK: };
|
||||
// CHECK: typedef enum _PACKED my_commented_enum my_commented_enum;
|
||||
|
||||
!my_commented_enum = !clift.enum<
|
||||
"/type-definition/0-EnumDefinition" as "my_commented_enum" : !uint64_t {
|
||||
|
||||
Reference in New Issue
Block a user