Skip to content

Commit

Permalink
Merge pull request #674 from andreasfertig/clang19Compile
Browse files Browse the repository at this point in the history
Clang 19 compile
  • Loading branch information
andreasfertig authored Oct 21, 2024
2 parents a77baff + 1c512fa commit a84a979
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
52 changes: 50 additions & 2 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DecltypeType>(defaultArg.getTypePtrOrNull())) {
if(const auto decltypeType = dyn_cast_or_null<DecltypeType>(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
);
}
}

Expand All @@ -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()));
Expand Down Expand Up @@ -3008,9 +3025,29 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt)
mOutputFormatHelper.Append(kwUsingSpace, GetName(*stmt), hlpAssing);

if(auto* templateSpecializationType = underlyingType->getAs<TemplateSpecializationType>()) {
#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<ElaboratedType>()) {
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<ElaboratedType>()) {
InsertNamespace(elaboratedType->getQualifier());
}
#endif

StringStream stream{};
stream.Print(*templateSpecializationType);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<TemplateSpecializationType>(typeAsWritten->getType());
InsertTemplateArgs(*tmplSpecType);
} else {
InsertTemplateArgs(clsTemplateSpe.getTemplateArgs());
}
#endif
}
//-----------------------------------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions Insights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions InsightsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DependentTemplateSpecializationType>()->getKeyword()) {
fullNamespace.append(kwTemplateSpace);
if(auto* dependentSpecType = stmt->getAsType()->getAs<DependentTemplateSpecializationType>()) {
fullNamespace.append(GetElaboratedTypeKeyword(dependentSpecType->getKeyword()));
}

[[fallthrough]];
Expand Down

0 comments on commit a84a979

Please sign in to comment.