From 6a7eb68f3241c2e9d0444e02523db8f4350c08eb Mon Sep 17 00:00:00 2001 From: Andreas Fertig Date: Mon, 13 Jan 2025 15:26:43 +0100 Subject: [PATCH] Clean up compatibility with Clang 18 and earlier. --- ASTHelpers.cpp | 22 ++---------- CodeGenerator.cpp | 72 +++---------------------------------- CoroutinesCodeGenerator.cpp | 17 ++------- Insights.cpp | 2 -- 4 files changed, 9 insertions(+), 104 deletions(-) diff --git a/ASTHelpers.cpp b/ASTHelpers.cpp index e381f9b..2f13272 100644 --- a/ASTHelpers.cpp +++ b/ASTHelpers.cpp @@ -514,19 +514,8 @@ CXXRecordDecl* Struct(std::string_view name) auto getRecord = [&] { auto& ctx = GetGlobalAST(); - return CXXRecordDecl::Create(ctx, -#if IS_CLANG_NEWER_THAN(17) - TagTypeKind::Struct -#else - TTK_Struct -#endif - , - ctx.getTranslationUnitDecl(), - {}, - {}, - &ctx.Idents.get(name), - nullptr, - false); + return CXXRecordDecl::Create( + ctx, TagTypeKind::Struct, ctx.getTranslationUnitDecl(), {}, {}, &ctx.Idents.get(name), nullptr, false); }; auto* rd = getRecord(); @@ -710,12 +699,7 @@ CXXNewExpr* New(ArrayRef placementArgs, const Expr* expr, QualType t) placementArgs, SourceRange{}, std::optional{}, -#if IS_CLANG_NEWER_THAN(17) - CXXNewInitializationStyle::Parens -#else - CXXNewExpr::CallInit -#endif - , + CXXNewInitializationStyle::Parens, const_cast(expr), Ptr(t), ctx.getTrivialTypeSourceInfo(t), diff --git a/CodeGenerator.cpp b/CodeGenerator.cpp index 8cae2bc..7659aaf 100644 --- a/CodeGenerator.cpp +++ b/CodeGenerator.cpp @@ -967,12 +967,7 @@ class TemporaryDeclFinder : public StmtVisitor {}, &ctx.Idents.get(mTempName), expr->getType(), -#if IS_CLANG_NEWER_THAN(17) - ImplicitParamKind::Other -#else - ImplicitParamDecl::Other -#endif - ); + ImplicitParamKind::Other); #endif @@ -1208,17 +1203,7 @@ static bool IsPrimaryTemplatePackExpansionExpr(const ParenListExpr* stmt) void CodeGenerator::InsertArg(const LinkageSpecDecl* stmt) { - mOutputFormatHelper.Append("extern \"", - ( -#if IS_CLANG_NEWER_THAN(17) - LinkageSpecLanguageIDs::C -#else - LinkageSpecDecl::lang_c -#endif - == stmt->getLanguage()) - ? "C"sv - : "C++"sv, - "\""); + mOutputFormatHelper.Append("extern \"", (LinkageSpecLanguageIDs::C == stmt->getLanguage()) ? "C"sv : "C++"sv, "\""); mOutputFormatHelper.OpenScope(); for(const auto* decl : stmt->decls()) { @@ -1752,26 +1737,14 @@ void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list, if(tt->hasDefaultArgument() and not tt->defaultArgumentWasInherited()) { const auto& defaultArg = tt->getDefaultArgument(); - if(const auto decltypeType = dyn_cast_or_null(defaultArg - . -#if IS_CLANG_NEWER_THAN(18) - getArgument() - .getAsType() -#else - getTypePtrOrNull() -#endif - )) { + if(const auto decltypeType = dyn_cast_or_null(defaultArg.getArgument().getAsType())) { mOutputFormatHelper.Append(hlpAssing); InsertArg(decltypeType->getUnderlyingExpr()); } else { mOutputFormatHelper.Append(hlpAssing); - InsertTemplateArg(defaultArg -#if IS_CLANG_NEWER_THAN(18) - .getArgument() -#endif - ); + InsertTemplateArg(defaultArg.getArgument()); } } @@ -1788,11 +1761,7 @@ void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list, if(nonTmplParam->hasDefaultArgument()) { mOutputFormatHelper.Append(hlpAssing); -#if IS_CLANG_NEWER_THAN(18) InsertTemplateArg(nonTmplParam->getDefaultArgument().getArgument()); -#else - InsertArg(nonTmplParam->getDefaultArgument()); -#endif } } else { mOutputFormatHelper.Append(typeName, EllipsisSpace(nonTmplParam->isParameterPack())); @@ -3048,7 +3017,6 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt) mOutputFormatHelper.Append(kwUsingSpace, GetName(*stmt), hlpAssing); if(auto* templateSpecializationType = underlyingType->getAs()) { -#if IS_CLANG_NEWER_THAN(18) const bool carriesNamespace{[&] { if(const auto tn = templateSpecializationType->getTemplateName(); (TemplateName::QualifiedTemplate == tn.getKind()) or (TemplateName::DependentTemplate == tn.getKind())) { @@ -3066,11 +3034,6 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt) InsertNamespace(elaboratedType->getQualifier()); } } -#else - if(const auto* elaboratedType = underlyingType->getAs()) { - InsertNamespace(elaboratedType->getQualifier()); - } -#endif StringStream stream{}; stream.Print(*templateSpecializationType); @@ -3699,10 +3662,8 @@ void CodeGenerator::InsertAttribute(const Attr& attr) // skip this attribute. Clang seems to tag final methods or classes with final RETURN_IF(attr::Final == attr.getKind()); -#if IS_CLANG_NEWER_THAN(17) // skip this custom clang attribute RETURN_IF(attr::NoInline == attr.getKind()); -#endif // Clang's printPretty misses the parameter pack ellipsis. Hence treat this special case here. if(const auto* alignedAttr = dyn_cast_or_null(&attr)) { @@ -3740,12 +3701,6 @@ void CodeGenerator::InsertAttribute(const Attr& attr) // attributes start with a space, skip it as it is not required for the first attribute std::string_view start{stream.str()}; -#if IS_CLANG_NEWER_THAN(18) -#else - if(!start.empty()) { - start.remove_prefix(1); - } -#endif mOutputFormatHelper.Append(start, " "sv); } @@ -4485,20 +4440,11 @@ void CodeGenerator::InsertSuffix(const QualType& type) void CodeGenerator::InsertTemplateArgs(const ClassTemplateSpecializationDecl& clsTemplateSpe) { -#if IS_CLANG_NEWER_THAN(18) if(const auto* ar = clsTemplateSpe.getTemplateArgsAsWritten()) { InsertTemplateArgs(ar->arguments()); } else { InsertTemplateArgs(clsTemplateSpe.getTemplateArgs()); } -#else - if(const TypeSourceInfo* typeAsWritten = clsTemplateSpe.getTypeAsWritten()) { - const TemplateSpecializationType* tmplSpecType = cast(typeAsWritten->getType()); - InsertTemplateArgs(*tmplSpecType); - } else { - InsertTemplateArgs(clsTemplateSpe.getTemplateArgs()); - } -#endif } //----------------------------------------------------------------------------- @@ -4536,9 +4482,7 @@ void CodeGenerator::InsertTemplateArg(const TemplateArgument& arg) mOutputFormatHelper.Append(GetName(*arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl())); break; case TemplateArgument::Null: mOutputFormatHelper.Append("null"sv); break; -#if IS_CLANG_NEWER_THAN(17) case TemplateArgument::StructuralValue: ToDo(arg, mOutputFormatHelper); break; -#endif } } //----------------------------------------------------------------------------- @@ -4567,10 +4511,6 @@ void CodeGenerator::HandleLocalStaticNonTrivialClass(const VarDecl* stmt) ctx.getConstantArrayType(ctx.CharTy, llvm::APInt(ctx.getTypeSize(ctx.getSizeType()), 0), Sizeof(stmt->getType()), -#if IS_CLANG_NEWER_THAN(17) -#else - ArrayType:: -#endif ArraySizeModifier::Normal, 0)); @@ -4979,11 +4919,7 @@ void CodeGenerator::InsertFunctionNameWithReturnType(const FunctionDecl& d // template requires-clause during creation of the template head. InsertConceptConstraint(&decl); -#if IS_CLANG_NEWER_THAN(17) if(decl.isPureVirtual()) { -#else - if(decl.isPure()) { -#endif mOutputFormatHelper.Append(" = 0"sv); } diff --git a/CoroutinesCodeGenerator.cpp b/CoroutinesCodeGenerator.cpp index 390b34b..c3bf704 100644 --- a/CoroutinesCodeGenerator.cpp +++ b/CoroutinesCodeGenerator.cpp @@ -532,13 +532,7 @@ void CoroutinesCodeGenerator::InsertCoroutine(const FunctionDecl& fd, const Coro if(const auto* cxxMethodDecl = dyn_cast_or_null(&fd)) { funParamStorage.reserve(funParams.size() + 1); - cxxMethodType = cxxMethodDecl-> -#if IS_CLANG_NEWER_THAN(17) - getFunctionObjectParameterType() -#else - getThisObjectType() -#endif - ; + cxxMethodType = cxxMethodDecl->getFunctionObjectParameterType(); // In case we have a member function the first parameter is a reference to this. The following code injects // this parameter. @@ -574,14 +568,7 @@ void CoroutinesCodeGenerator::InsertCoroutine(const FunctionDecl& fd, const Coro if(not ctor->param_empty() and (getNonRefType(ctor->getParamDecl(0)) == QualType(cxxMethodType.getTypePtrOrNull(), 0))) { if(0 == mASTData.mThisExprs.size()) { - mASTData.mThisExprs.push_back( -#if IS_CLANG_NEWER_THAN(17) - CXXThisExpr::Create(ctx, {}, Ptr(cxxMethodType), false) -#else - new(ctx) CXXThisExpr{{}, Ptr(cxxMethodType), false} -#endif - - ); + mASTData.mThisExprs.push_back(CXXThisExpr::Create(ctx, {}, Ptr(cxxMethodType), false)); } } else { (void)static_cast(derefFirstParam); // set it to false diff --git a/Insights.cpp b/Insights.cpp index 2416bb2..4f57e7c 100644 --- a/Insights.cpp +++ b/Insights.cpp @@ -136,9 +136,7 @@ class FindIncludes : public PPCallbacks StringRef /*SearchPath*/, StringRef /*RelativePath*/, const Module* /*Imported*/, -#if IS_CLANG_NEWER_THAN(18) bool /*ModuleImported*/, -#endif SrcMgr::CharacteristicKind /*FileType*/) override { auto expansionLoc = mSm.getExpansionLoc(hashLoc);