Skip to content

Commit 1324b32

Browse files
committed
[clang] Add API to iterate already loaded specializations
This avoids deserialization if necessary, for example in DeclUnloader. See also https://reviews.llvm.org/D154328
1 parent b90bab0 commit 1324b32

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

interpreter/cling/lib/Interpreter/DeclUnloader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,8 @@ bool DeclUnloader::VisitRedeclarable(clang::Redeclarable<T>* R, DeclContext* DC)
941941
bool Successful = true;
942942

943943
// Remove specializations:
944-
for (FunctionTemplateDecl::spec_iterator I = FTD->spec_begin(),
945-
E = FTD->spec_end(); I != E; ++I)
944+
for (FunctionTemplateDecl::spec_iterator I = FTD->loaded_spec_begin(),
945+
E = FTD->loaded_spec_end(); I != E; ++I)
946946
Successful &= Visit(*I);
947947

948948
Successful &= VisitRedeclarableTemplateDecl(FTD);
@@ -954,8 +954,8 @@ bool DeclUnloader::VisitRedeclarable(clang::Redeclarable<T>* R, DeclContext* DC)
954954
// ClassTemplateDecl: TemplateDecl, Redeclarable
955955
bool Successful = true;
956956
// Remove specializations:
957-
for (ClassTemplateDecl::spec_iterator I = CTD->spec_begin(),
958-
E = CTD->spec_end(); I != E; ++I)
957+
for (ClassTemplateDecl::spec_iterator I = CTD->loaded_spec_begin(),
958+
E = CTD->loaded_spec_end(); I != E; ++I)
959959
Successful &= Visit(*I);
960960

961961
Successful &= VisitRedeclarableTemplateDecl(CTD);

interpreter/llvm-project/clang/include/clang/AST/DeclTemplate.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,20 @@ class FunctionTemplateDecl : public RedeclarableTemplateDecl {
11191119
return makeSpecIterator(getSpecializations(), true);
11201120
}
11211121

1122+
/// All specializations that that have already been loaded, ie avoiding
1123+
/// deserialization of lazily registered specializations.
1124+
spec_range loaded_specializations() const {
1125+
return spec_range(loaded_spec_begin(), loaded_spec_end());
1126+
}
1127+
1128+
spec_iterator loaded_spec_begin() const {
1129+
return makeSpecIterator(getCommonPtr()->Specializations, false);
1130+
}
1131+
1132+
spec_iterator loaded_spec_end() const {
1133+
return makeSpecIterator(getCommonPtr()->Specializations, true);
1134+
}
1135+
11221136
/// Retrieve the "injected" template arguments that correspond to the
11231137
/// template parameters of this function template.
11241138
///
@@ -2448,6 +2462,20 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
24482462
return makeSpecIterator(getSpecializations(), true);
24492463
}
24502464

2465+
/// All specializations that that have already been loaded, ie avoiding
2466+
/// deserialization of lazily registered specializations.
2467+
spec_range loaded_specializations() const {
2468+
return spec_range(loaded_spec_begin(), loaded_spec_end());
2469+
}
2470+
2471+
spec_iterator loaded_spec_begin() const {
2472+
return makeSpecIterator(getCommonPtr()->Specializations, false);
2473+
}
2474+
2475+
spec_iterator loaded_spec_end() const {
2476+
return makeSpecIterator(getCommonPtr()->Specializations, true);
2477+
}
2478+
24512479
// Implement isa/cast/dyncast support
24522480
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
24532481
static bool classofKind(Kind K) { return K == ClassTemplate; }
@@ -3251,6 +3279,20 @@ class VarTemplateDecl : public RedeclarableTemplateDecl {
32513279
return makeSpecIterator(getSpecializations(), true);
32523280
}
32533281

3282+
/// All specializations that that have already been loaded, ie avoiding
3283+
/// deserialization of lazily registered specializations.
3284+
spec_range loaded_specializations() const {
3285+
return spec_range(loaded_spec_begin(), loaded_spec_end());
3286+
}
3287+
3288+
spec_iterator loaded_spec_begin() const {
3289+
return makeSpecIterator(getCommonPtr()->Specializations, false);
3290+
}
3291+
3292+
spec_iterator loaded_spec_end() const {
3293+
return makeSpecIterator(getCommonPtr()->Specializations, true);
3294+
}
3295+
32543296
// Implement isa/cast/dyncast support
32553297
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
32563298
static bool classofKind(Kind K) { return K == VarTemplate; }

0 commit comments

Comments
 (0)