From 1c512fa0a8ae936887118147a5a05508228136c2 Mon Sep 17 00:00:00 2001 From: Andreas Fertig Date: Mon, 21 Oct 2024 16:01:28 +0200 Subject: [PATCH] Clang 19 compile --- CodeGenerator.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++-- Insights.cpp | 3 +++ InsightsHelpers.cpp | 10 ++------- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/CodeGenerator.cpp b/CodeGenerator.cpp index 026ed07..3d66767 100644 --- a/CodeGenerator.cpp +++ b/CodeGenerator.cpp @@ -1729,13 +1729,26 @@ 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.getTypePtrOrNull())) { + if(const auto decltypeType = dyn_cast_or_null(defaultArg + . +#if IS_CLANG_NEWER_THAN(18) + getArgument() + .getAsType() +#else + getTypePtrOrNull() +#endif + )) { mOutputFormatHelper.Append(hlpAssing); InsertArg(decltypeType->getUnderlyingExpr()); } else { - mOutputFormatHelper.Append(hlpAssing, GetName(defaultArg)); + mOutputFormatHelper.Append(hlpAssing); + InsertTemplateArg(defaultArg +#if IS_CLANG_NEWER_THAN(18) + .getArgument() +#endif + ); } } @@ -1752,7 +1765,11 @@ 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())); @@ -3008,9 +3025,29 @@ 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())) { + const auto* qtn = tn.getAsQualifiedTemplateName(); + + return qtn->getQualifier() != nullptr; + } + + return false; + }()}; + + if(const auto* elaboratedType = underlyingType->getAs()) { + if(templateSpecializationType->isSugared() and not carriesNamespace) { + // do this only if the templateSpecializationType does not carry a nestedns + InsertNamespace(elaboratedType->getQualifier()); + } + } +#else if(const auto* elaboratedType = underlyingType->getAs()) { InsertNamespace(elaboratedType->getQualifier()); } +#endif StringStream stream{}; stream.Print(*templateSpecializationType); @@ -3686,7 +3723,10 @@ 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 start.remove_prefix(1); +#endif mOutputFormatHelper.Append(start, " "sv); } @@ -4426,12 +4466,20 @@ 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 } //----------------------------------------------------------------------------- diff --git a/Insights.cpp b/Insights.cpp index 11dce30..578aa87 100644 --- a/Insights.cpp +++ b/Insights.cpp @@ -130,6 +130,9 @@ 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); diff --git a/InsightsHelpers.cpp b/InsightsHelpers.cpp index 85bfec6..f2cc54b 100644 --- a/InsightsHelpers.cpp +++ b/InsightsHelpers.cpp @@ -180,14 +180,8 @@ BuildNamespace(std::string& fullNamespace, const NestedNameSpecifier* stmt, cons case NestedNameSpecifier::NamespaceAlias: fullNamespace.append(stmt->getAsNamespaceAlias()->getName()); break; case NestedNameSpecifier::TypeSpecWithTemplate: - if( -#if IS_CLANG_NEWER_THAN(17) - ElaboratedTypeKeyword::Typename -#else - ElaboratedTypeKeyword::ETK_Typename -#endif - == stmt->getAsType()->getAs()->getKeyword()) { - fullNamespace.append(kwTemplateSpace); + if(auto* dependentSpecType = stmt->getAsType()->getAs()) { + fullNamespace.append(GetElaboratedTypeKeyword(dependentSpecType->getKeyword())); } [[fallthrough]];