Skip to content

Commit 6a7eb68

Browse files
committed
Clean up compatibility with Clang 18 and earlier.
1 parent f243226 commit 6a7eb68

File tree

4 files changed

+9
-104
lines changed

4 files changed

+9
-104
lines changed

ASTHelpers.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,8 @@ CXXRecordDecl* Struct(std::string_view name)
514514
auto getRecord = [&] {
515515
auto& ctx = GetGlobalAST();
516516

517-
return CXXRecordDecl::Create(ctx,
518-
#if IS_CLANG_NEWER_THAN(17)
519-
TagTypeKind::Struct
520-
#else
521-
TTK_Struct
522-
#endif
523-
,
524-
ctx.getTranslationUnitDecl(),
525-
{},
526-
{},
527-
&ctx.Idents.get(name),
528-
nullptr,
529-
false);
517+
return CXXRecordDecl::Create(
518+
ctx, TagTypeKind::Struct, ctx.getTranslationUnitDecl(), {}, {}, &ctx.Idents.get(name), nullptr, false);
530519
};
531520

532521
auto* rd = getRecord();
@@ -710,12 +699,7 @@ CXXNewExpr* New(ArrayRef<Expr*> placementArgs, const Expr* expr, QualType t)
710699
placementArgs,
711700
SourceRange{},
712701
std::optional<Expr*>{},
713-
#if IS_CLANG_NEWER_THAN(17)
714-
CXXNewInitializationStyle::Parens
715-
#else
716-
CXXNewExpr::CallInit
717-
#endif
718-
,
702+
CXXNewInitializationStyle::Parens,
719703
const_cast<Expr*>(expr),
720704
Ptr(t),
721705
ctx.getTrivialTypeSourceInfo(t),

CodeGenerator.cpp

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,7 @@ class TemporaryDeclFinder : public StmtVisitor<TemporaryDeclFinder>
967967
{},
968968
&ctx.Idents.get(mTempName),
969969
expr->getType(),
970-
#if IS_CLANG_NEWER_THAN(17)
971-
ImplicitParamKind::Other
972-
#else
973-
ImplicitParamDecl::Other
974-
#endif
975-
);
970+
ImplicitParamKind::Other);
976971

977972
#endif
978973

@@ -1208,17 +1203,7 @@ static bool IsPrimaryTemplatePackExpansionExpr(const ParenListExpr* stmt)
12081203

12091204
void CodeGenerator::InsertArg(const LinkageSpecDecl* stmt)
12101205
{
1211-
mOutputFormatHelper.Append("extern \"",
1212-
(
1213-
#if IS_CLANG_NEWER_THAN(17)
1214-
LinkageSpecLanguageIDs::C
1215-
#else
1216-
LinkageSpecDecl::lang_c
1217-
#endif
1218-
== stmt->getLanguage())
1219-
? "C"sv
1220-
: "C++"sv,
1221-
"\"");
1206+
mOutputFormatHelper.Append("extern \"", (LinkageSpecLanguageIDs::C == stmt->getLanguage()) ? "C"sv : "C++"sv, "\"");
12221207
mOutputFormatHelper.OpenScope();
12231208

12241209
for(const auto* decl : stmt->decls()) {
@@ -1752,26 +1737,14 @@ void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list,
17521737
if(tt->hasDefaultArgument() and not tt->defaultArgumentWasInherited()) {
17531738
const auto& defaultArg = tt->getDefaultArgument();
17541739

1755-
if(const auto decltypeType = dyn_cast_or_null<DecltypeType>(defaultArg
1756-
.
1757-
#if IS_CLANG_NEWER_THAN(18)
1758-
getArgument()
1759-
.getAsType()
1760-
#else
1761-
getTypePtrOrNull()
1762-
#endif
1763-
)) {
1740+
if(const auto decltypeType = dyn_cast_or_null<DecltypeType>(defaultArg.getArgument().getAsType())) {
17641741
mOutputFormatHelper.Append(hlpAssing);
17651742

17661743
InsertArg(decltypeType->getUnderlyingExpr());
17671744

17681745
} else {
17691746
mOutputFormatHelper.Append(hlpAssing);
1770-
InsertTemplateArg(defaultArg
1771-
#if IS_CLANG_NEWER_THAN(18)
1772-
.getArgument()
1773-
#endif
1774-
);
1747+
InsertTemplateArg(defaultArg.getArgument());
17751748
}
17761749
}
17771750

@@ -1788,11 +1761,7 @@ void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list,
17881761

17891762
if(nonTmplParam->hasDefaultArgument()) {
17901763
mOutputFormatHelper.Append(hlpAssing);
1791-
#if IS_CLANG_NEWER_THAN(18)
17921764
InsertTemplateArg(nonTmplParam->getDefaultArgument().getArgument());
1793-
#else
1794-
InsertArg(nonTmplParam->getDefaultArgument());
1795-
#endif
17961765
}
17971766
} else {
17981767
mOutputFormatHelper.Append(typeName, EllipsisSpace(nonTmplParam->isParameterPack()));
@@ -3048,7 +3017,6 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt)
30483017
mOutputFormatHelper.Append(kwUsingSpace, GetName(*stmt), hlpAssing);
30493018

30503019
if(auto* templateSpecializationType = underlyingType->getAs<TemplateSpecializationType>()) {
3051-
#if IS_CLANG_NEWER_THAN(18)
30523020
const bool carriesNamespace{[&] {
30533021
if(const auto tn = templateSpecializationType->getTemplateName();
30543022
(TemplateName::QualifiedTemplate == tn.getKind()) or (TemplateName::DependentTemplate == tn.getKind())) {
@@ -3066,11 +3034,6 @@ void CodeGenerator::InsertArg(const TypeAliasDecl* stmt)
30663034
InsertNamespace(elaboratedType->getQualifier());
30673035
}
30683036
}
3069-
#else
3070-
if(const auto* elaboratedType = underlyingType->getAs<ElaboratedType>()) {
3071-
InsertNamespace(elaboratedType->getQualifier());
3072-
}
3073-
#endif
30743037

30753038
StringStream stream{};
30763039
stream.Print(*templateSpecializationType);
@@ -3699,10 +3662,8 @@ void CodeGenerator::InsertAttribute(const Attr& attr)
36993662
// skip this attribute. Clang seems to tag final methods or classes with final
37003663
RETURN_IF(attr::Final == attr.getKind());
37013664

3702-
#if IS_CLANG_NEWER_THAN(17)
37033665
// skip this custom clang attribute
37043666
RETURN_IF(attr::NoInline == attr.getKind());
3705-
#endif
37063667

37073668
// Clang's printPretty misses the parameter pack ellipsis. Hence treat this special case here.
37083669
if(const auto* alignedAttr = dyn_cast_or_null<AlignedAttr>(&attr)) {
@@ -3740,12 +3701,6 @@ void CodeGenerator::InsertAttribute(const Attr& attr)
37403701

37413702
// attributes start with a space, skip it as it is not required for the first attribute
37423703
std::string_view start{stream.str()};
3743-
#if IS_CLANG_NEWER_THAN(18)
3744-
#else
3745-
if(!start.empty()) {
3746-
start.remove_prefix(1);
3747-
}
3748-
#endif
37493704

37503705
mOutputFormatHelper.Append(start, " "sv);
37513706
}
@@ -4485,20 +4440,11 @@ void CodeGenerator::InsertSuffix(const QualType& type)
44854440

44864441
void CodeGenerator::InsertTemplateArgs(const ClassTemplateSpecializationDecl& clsTemplateSpe)
44874442
{
4488-
#if IS_CLANG_NEWER_THAN(18)
44894443
if(const auto* ar = clsTemplateSpe.getTemplateArgsAsWritten()) {
44904444
InsertTemplateArgs(ar->arguments());
44914445
} else {
44924446
InsertTemplateArgs(clsTemplateSpe.getTemplateArgs());
44934447
}
4494-
#else
4495-
if(const TypeSourceInfo* typeAsWritten = clsTemplateSpe.getTypeAsWritten()) {
4496-
const TemplateSpecializationType* tmplSpecType = cast<TemplateSpecializationType>(typeAsWritten->getType());
4497-
InsertTemplateArgs(*tmplSpecType);
4498-
} else {
4499-
InsertTemplateArgs(clsTemplateSpe.getTemplateArgs());
4500-
}
4501-
#endif
45024448
}
45034449
//-----------------------------------------------------------------------------
45044450

@@ -4536,9 +4482,7 @@ void CodeGenerator::InsertTemplateArg(const TemplateArgument& arg)
45364482
mOutputFormatHelper.Append(GetName(*arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl()));
45374483
break;
45384484
case TemplateArgument::Null: mOutputFormatHelper.Append("null"sv); break;
4539-
#if IS_CLANG_NEWER_THAN(17)
45404485
case TemplateArgument::StructuralValue: ToDo(arg, mOutputFormatHelper); break;
4541-
#endif
45424486
}
45434487
}
45444488
//-----------------------------------------------------------------------------
@@ -4567,10 +4511,6 @@ void CodeGenerator::HandleLocalStaticNonTrivialClass(const VarDecl* stmt)
45674511
ctx.getConstantArrayType(ctx.CharTy,
45684512
llvm::APInt(ctx.getTypeSize(ctx.getSizeType()), 0),
45694513
Sizeof(stmt->getType()),
4570-
#if IS_CLANG_NEWER_THAN(17)
4571-
#else
4572-
ArrayType::
4573-
#endif
45744514
ArraySizeModifier::Normal,
45754515
0));
45764516

@@ -4979,11 +4919,7 @@ void CodeGenerator::InsertFunctionNameWithReturnType(const FunctionDecl& d
49794919
// template requires-clause during creation of the template head.
49804920
InsertConceptConstraint(&decl);
49814921

4982-
#if IS_CLANG_NEWER_THAN(17)
49834922
if(decl.isPureVirtual()) {
4984-
#else
4985-
if(decl.isPure()) {
4986-
#endif
49874923
mOutputFormatHelper.Append(" = 0"sv);
49884924
}
49894925

CoroutinesCodeGenerator.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,7 @@ void CoroutinesCodeGenerator::InsertCoroutine(const FunctionDecl& fd, const Coro
532532
if(const auto* cxxMethodDecl = dyn_cast_or_null<CXXMethodDecl>(&fd)) {
533533
funParamStorage.reserve(funParams.size() + 1);
534534

535-
cxxMethodType = cxxMethodDecl->
536-
#if IS_CLANG_NEWER_THAN(17)
537-
getFunctionObjectParameterType()
538-
#else
539-
getThisObjectType()
540-
#endif
541-
;
535+
cxxMethodType = cxxMethodDecl->getFunctionObjectParameterType();
542536

543537
// In case we have a member function the first parameter is a reference to this. The following code injects
544538
// this parameter.
@@ -574,14 +568,7 @@ void CoroutinesCodeGenerator::InsertCoroutine(const FunctionDecl& fd, const Coro
574568
if(not ctor->param_empty() and
575569
(getNonRefType(ctor->getParamDecl(0)) == QualType(cxxMethodType.getTypePtrOrNull(), 0))) {
576570
if(0 == mASTData.mThisExprs.size()) {
577-
mASTData.mThisExprs.push_back(
578-
#if IS_CLANG_NEWER_THAN(17)
579-
CXXThisExpr::Create(ctx, {}, Ptr(cxxMethodType), false)
580-
#else
581-
new(ctx) CXXThisExpr{{}, Ptr(cxxMethodType), false}
582-
#endif
583-
584-
);
571+
mASTData.mThisExprs.push_back(CXXThisExpr::Create(ctx, {}, Ptr(cxxMethodType), false));
585572
}
586573
} else {
587574
(void)static_cast<bool>(derefFirstParam); // set it to false

Insights.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ class FindIncludes : public PPCallbacks
136136
StringRef /*SearchPath*/,
137137
StringRef /*RelativePath*/,
138138
const Module* /*Imported*/,
139-
#if IS_CLANG_NEWER_THAN(18)
140139
bool /*ModuleImported*/,
141-
#endif
142140
SrcMgr::CharacteristicKind /*FileType*/) override
143141
{
144142
auto expansionLoc = mSm.getExpansionLoc(hashLoc);

0 commit comments

Comments
 (0)