| 3798 | //----------------------------------------------------------------------------- |
| 3799 | |
| 3800 | void CodeGenerator::InsertAttribute(const Attr& attr) |
| 3801 | { |
| 3802 | // skip this attribute. Clang seems to tag virtual methods with override |
| 3803 | RETURN_IF(attr::Override == attr.getKind()); |
| 3804 | |
| 3805 | // skip this attribute. Clang seems to tag final methods or classes with final |
| 3806 | RETURN_IF(attr::Final == attr.getKind()); |
| 3807 | |
| 3808 | // skip this custom clang attribute |
| 3809 | RETURN_IF(attr::NoInline == attr.getKind()); |
| 3810 | |
| 3811 | #if IS_CLANG_NEWER_THAN(20) |
| 3812 | // skip this custom clang attribute |
| 3813 | RETURN_IF(attr::InferredNoReturn == attr.getKind()); |
| 3814 | #endif |
| 3815 | |
| 3816 | // Clang's printPretty misses the parameter pack ellipsis. Hence treat this special case here. |
| 3817 | if(const auto* alignedAttr = dyn_cast_or_null<AlignedAttr>(&attr)) { |
| 3818 | auto insert = [&](const QualType type, const TemplateTypeParmType* tmplTypeParam) { |
| 3819 | mOutputFormatHelper.Append(attr.getSpelling(), |
| 3820 | "("sv, |
| 3821 | kwAlignof, |
| 3822 | "("sv, |
| 3823 | GetName(type), |
| 3824 | ")"sv, |
| 3825 | Ellipsis(tmplTypeParam->isParameterPack()), |
| 3826 | ") "sv); |
| 3827 | }; |
| 3828 | |
| 3829 | if(alignedAttr->isAlignmentExpr()) { |
| 3830 | if(const auto* unaryExpr = dyn_cast_or_null<UnaryExprOrTypeTraitExpr>(alignedAttr->getAlignmentExpr())) { |
| 3831 | if(const auto* tmplTypeParam = |
| 3832 | dyn_cast_or_null<TemplateTypeParmType>(unaryExpr->getArgumentType().getTypePtrOrNull())) { |
| 3833 | insert(unaryExpr->getArgumentType(), tmplTypeParam); |
| 3834 | return; |
| 3835 | } |
| 3836 | } |
| 3837 | } else if(const auto* tmplTypeParam = |
| 3838 | alignedAttr->getAlignmentType()->getType()->getAs<TemplateTypeParmType>()) { |
| 3839 | insert(alignedAttr->getAlignmentType()->getType(), tmplTypeParam); |
| 3840 | return; |
| 3841 | } |
| 3842 | } |
| 3843 | |
| 3844 | StringStream stream{}; |
| 3845 | PrintingPolicy pp{GetGlobalAST().getLangOpts()}; |
| 3846 | pp.adjustForCPlusPlus(); |
| 3847 | |
| 3848 | attr.printPretty(stream, pp); |
| 3849 | |
| 3850 | // attributes start with a space, skip it as it is not required for the first attribute |
| 3851 | std::string_view start{stream.str()}; |
| 3852 | |
| 3853 | mOutputFormatHelper.Append(start, " "sv); |
| 3854 | } |
| 3855 | //----------------------------------------------------------------------------- |
| 3856 | |
| 3857 | void CodeGenerator::InsertArg(const CXXRecordDecl* stmt) |