Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang_delta/CommonParameterRewriteVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ bool CommonParameterRewriteVisitor<T, Trans>::VisitCallExpr(
(DName.getNameKind() ==
clang::DeclarationName::CXXOperatorName)) &&
"Not an indentifier!");
#if LLVM_VERSION_MAJOR >= 22
if (clang::NestedNameSpecifier NNS = UE->getQualifier()) {
#else
if (const clang::NestedNameSpecifier *NNS = UE->getQualifier()) {
#endif
if (const clang::DeclContext *Ctx =
ConsumerInstance->getDeclContextFromSpecifier(NNS)) {
DeclContextSet VisitedCtxs;
Expand Down
8 changes: 8 additions & 0 deletions clang_delta/CommonRenameClassRewriteVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ class CommonRenameClassRewriteVisitor : public RecursiveASTVisitor<T> {

bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);

#if LLVM_VERSION_MAJOR < 22
bool VisitDependentTemplateSpecializationTypeLoc(
DependentTemplateSpecializationTypeLoc DTSLoc);
#endif

bool VisitClassTemplateSpecializationDecl(
ClassTemplateSpecializationDecl *TSD);
Expand Down Expand Up @@ -301,6 +303,7 @@ bool CommonRenameClassRewriteVisitor<T>::VisitRecordTypeLoc(RecordTypeLoc RTLoc)
return true;
}

#if LLVM_VERSION_MAJOR < 22
template<typename T> bool CommonRenameClassRewriteVisitor<T>::
VisitDependentTemplateSpecializationTypeLoc(
DependentTemplateSpecializationTypeLoc DTSLoc)
Expand All @@ -310,7 +313,11 @@ template<typename T> bool CommonRenameClassRewriteVisitor<T>::
dyn_cast<DependentTemplateSpecializationType>(Ty);
TransAssert(DTST && "Bad DependentTemplateSpecializationType!");

#if LLVM_VERSION_MAJOR >= 21
const IdentifierInfo *IdInfo = DTST->getDependentTemplateName().getName().getIdentifier();
#else
const IdentifierInfo *IdInfo = DTST->getIdentifier();
#endif
std::string IdName = IdInfo->getName().str();
std::string Name;
if (getNewNameByName(IdName, Name)) {
Expand All @@ -320,6 +327,7 @@ template<typename T> bool CommonRenameClassRewriteVisitor<T>::

return true;
}
#endif

template<typename T>
void CommonRenameClassRewriteVisitor<T>::renameTemplateName(
Expand Down
4 changes: 4 additions & 0 deletions clang_delta/EmptyStructToInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class EmptyStructToIntRewriteVisitor : public

bool VisitRecordTypeLoc(RecordTypeLoc RTLoc);

#if LLVM_VERSION_MAJOR < 22
bool VisitElaboratedTypeLoc(ElaboratedTypeLoc Loc);
#endif

bool VisitRecordDecl(RecordDecl *RD);

Expand Down Expand Up @@ -137,6 +139,7 @@ bool EmptyStructToIntRewriteVisitor::VisitRecordTypeLoc(RecordTypeLoc RTLoc)
return true;
}

#if LLVM_VERSION_MAJOR < 22
bool EmptyStructToIntRewriteVisitor::VisitElaboratedTypeLoc(
ElaboratedTypeLoc Loc)
{
Expand Down Expand Up @@ -195,6 +198,7 @@ bool EmptyStructToIntRewriteVisitor::VisitElaboratedTypeLoc(
ConsumerInstance->TheRewriter.RemoveText(SourceRange(StartLoc, EndLoc));
return true;
}
#endif

bool EmptyStructToIntRewriteVisitor::VisitRecordDecl(RecordDecl *RD)
{
Expand Down
29 changes: 27 additions & 2 deletions clang_delta/ExpressionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class IncludesPPCallbacks : public PPCallbacks {
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath,
const Module *Imported,
const Module *SuggestedModule,
bool ModuleImported,
SrcMgr::CharacteristicKind FileType) override;

private:
Expand All @@ -85,7 +86,8 @@ void IncludesPPCallbacks::InclusionDirective(SourceLocation HashLoc,
OptionalFileEntryRef /*File*/,
StringRef /*SearchPath*/,
StringRef /*RelativePath*/,
const Module * /*Imported*/,
const Module * /*SuggestedModule*/,
bool /*ModuleImported*/,
SrcMgr::CharacteristicKind /*FileType*/)
{
if (!SrcManager.isInMainFile(HashLoc))
Expand Down Expand Up @@ -118,7 +120,11 @@ bool LocalTmpVarCollector::VisitDeclRefExpr(DeclRefExpr *DRE)
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl());
if (!VD)
return true;
#if LLVM_VERSION_MAJOR >= 19
if (VD->getName().starts_with(Prefix))
#else
if (VD->getName().startswith(Prefix))
#endif
TmpVars.push_back(VD);
return true;
}
Expand Down Expand Up @@ -363,7 +369,11 @@ void ExpressionDetector::addOneTempVar(const VarDecl *VD)
{
if (!VD)
return;
#if LLVM_VERSION_MAJOR >= 19
if (!VD->getName().starts_with(TmpVarNamePrefix))
#else
if (!VD->getName().startswith(TmpVarNamePrefix))
#endif
return;
if (const Expr *E = VD->getInit())
ProcessedExprs[VD] = E->IgnoreParenImpCasts();
Expand All @@ -374,9 +384,15 @@ bool ExpressionDetector::refToTmpVar(const NamedDecl *ND)
StringRef Name = ND->getName();
// We don't want to repeatly replace temporary variables
// __creduce_expr_tmp_xxx, __creduce_printed_yy and __creduce_checked_zzz.
#if LLVM_VERSION_MAJOR >= 19
return Name.starts_with(TmpVarNamePrefix) ||
Name.starts_with(PrintedVarNamePrefix) ||
Name.starts_with(CheckedVarNamePrefix);
#else
return Name.startswith(TmpVarNamePrefix) ||
Name.startswith(PrintedVarNamePrefix) ||
Name.startswith(CheckedVarNamePrefix);
#endif
}

// Reference: IdenticalExprChecker.cpp from Clang
Expand Down Expand Up @@ -524,8 +540,13 @@ bool ExpressionDetector::isValidExpr(Stmt *S, const Expr *E)
if (const DeclRefExpr *SubE =
dyn_cast<DeclRefExpr>(UO->getSubExpr()->IgnoreParenCasts())) {
StringRef SubEName = SubE->getDecl()->getName();
#if LLVM_VERSION_MAJOR >= 19
if (SubEName.starts_with(PrintedVarNamePrefix) ||
SubEName.starts_with(CheckedVarNamePrefix))
#else
if (SubEName.startswith(PrintedVarNamePrefix) ||
SubEName.startswith(CheckedVarNamePrefix))
#endif
return false;
}
}
Expand All @@ -541,7 +562,11 @@ bool ExpressionDetector::isValidExpr(Stmt *S, const Expr *E)
bool IsLit = SC == Stmt::IntegerLiteralClass ||
SC == Stmt::FloatingLiteralClass;
if (IsLit && DRE &&
#if LLVM_VERSION_MAJOR >= 19
DRE->getDecl()->getName().starts_with(TmpVarNamePrefix) &&
#else
DRE->getDecl()->getName().startswith(TmpVarNamePrefix) &&
#endif
S->getStmtClass() == Stmt::IfStmtClass) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions clang_delta/InstantiateTemplateParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,12 @@ bool InstantiateTemplateParam::getTypeString(
Type::TypeClass TC = Ty->getTypeClass();

switch (TC) {
#if LLVM_VERSION_MAJOR < 22
case Type::Elaborated: {
const ElaboratedType *ETy = dyn_cast<ElaboratedType>(Ty);
return getTypeString(ETy->getNamedType(), Str, ForwardStr);
}
#endif

case Type::Typedef: {
const TypedefType *TdefTy = dyn_cast<TypedefType>(Ty);
Expand Down
9 changes: 9 additions & 0 deletions clang_delta/RemoveBaseClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ void RemoveBaseClass::copyBaseClassDecls(void)

bool RemoveBaseClass::isTheBaseClass(const CXXBaseSpecifier &Specifier)
{
#if LLVM_VERSION_MAJOR >= 22
const Type *Ty = Context->getCanonicalTagType(TheBaseClass).getTypePtr();
#else
const Type *Ty = TheBaseClass->getTypeForDecl();
#endif
return Context->hasSameType(Specifier.getType(),
Ty->getCanonicalTypeInternal());
}
Expand Down Expand Up @@ -276,7 +280,12 @@ void RemoveBaseClass::rewriteOneCtor(const CXXConstructorDecl *Ctor)
const Type *Ty = (*I)->getBaseClass();
TransAssert(Ty && "Invalid Base Class Type!");
if (Context->hasSameType(Ty->getCanonicalTypeInternal(),
#if LLVM_VERSION_MAJOR >= 22
Context->getCanonicalTagType(TheBaseClass).getTypePtr()
->getCanonicalTypeInternal())) {
#else
TheBaseClass->getTypeForDecl()->getCanonicalTypeInternal())) {
#endif
Init = (*I);
break;
}
Expand Down
Loading