================
@@ -1843,6 +1843,21 @@ void
StmtPrinter::VisitMatrixElementExpr(MatrixElementExpr *Node) {
}
void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
+ // special case enums to avoid producing cast expressions when naming
+ // an enumerator would suffice
+ if (QualType T = Node->getType(); T->isEnumeralType()) {
+ const auto *IL = dyn_cast<IntegerLiteral>(Node->getSubExpr());
+ const auto *ED = T->getAsEnumDecl();
+ if (IL && ED) {
+ llvm::APInt Val = IL->getValue();
+ for (const EnumConstantDecl *ECD : ED->enumerators()) {
+ if (llvm::APInt::isSameValue(ECD->getInitVal(), Val)) {
+ ECD->printQualifiedName(OS, Policy);
+ return;
----------------
cor3ntin wrote:
llvm::find_if?
https://github.com/llvm/llvm-project/pull/204682
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits