Skip to content

Commit 8e4d289

Browse files
committed
D154328: [AST] Add API to iterate already loaded specializations
These new functions allow to look at specializations without triggering deserialization, which might be problematic in some contexts.
1 parent 5ed1adf commit 8e4d289

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

clang/include/clang/AST/DeclTemplate.h

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

1087+
/// All specializations that that have already been loaded, ie avoiding
1088+
/// deserialization of lazily registered specializations.
1089+
spec_range loaded_specializations() const {
1090+
return spec_range(loaded_spec_begin(), loaded_spec_end());
1091+
}
1092+
1093+
spec_iterator loaded_spec_begin() const {
1094+
return makeSpecIterator(getCommonPtr()->Specializations, false);
1095+
}
1096+
1097+
spec_iterator loaded_spec_end() const {
1098+
return makeSpecIterator(getCommonPtr()->Specializations, true);
1099+
}
1100+
10871101
/// Return whether this function template is an abbreviated function template,
10881102
/// e.g. `void foo(auto x)` or `template<typename T> void foo(auto x)`
10891103
bool isAbbreviated() const {
@@ -2421,6 +2435,20 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
24212435
return makeSpecIterator(getSpecializations(), true);
24222436
}
24232437

2438+
/// All specializations that that have already been loaded, ie avoiding
2439+
/// deserialization of lazily registered specializations.
2440+
spec_range loaded_specializations() const {
2441+
return spec_range(loaded_spec_begin(), loaded_spec_end());
2442+
}
2443+
2444+
spec_iterator loaded_spec_begin() const {
2445+
return makeSpecIterator(getCommonPtr()->Specializations, false);
2446+
}
2447+
2448+
spec_iterator loaded_spec_end() const {
2449+
return makeSpecIterator(getCommonPtr()->Specializations, true);
2450+
}
2451+
24242452
// Implement isa/cast/dyncast support
24252453
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
24262454
static bool classofKind(Kind K) { return K == ClassTemplate; }
@@ -3166,6 +3194,20 @@ class VarTemplateDecl : public RedeclarableTemplateDecl {
31663194
return makeSpecIterator(getSpecializations(), true);
31673195
}
31683196

3197+
/// All specializations that that have already been loaded, ie avoiding
3198+
/// deserialization of lazily registered specializations.
3199+
spec_range loaded_specializations() const {
3200+
return spec_range(loaded_spec_begin(), loaded_spec_end());
3201+
}
3202+
3203+
spec_iterator loaded_spec_begin() const {
3204+
return makeSpecIterator(getCommonPtr()->Specializations, false);
3205+
}
3206+
3207+
spec_iterator loaded_spec_end() const {
3208+
return makeSpecIterator(getCommonPtr()->Specializations, true);
3209+
}
3210+
31693211
// Implement isa/cast/dyncast support
31703212
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
31713213
static bool classofKind(Kind K) { return K == VarTemplate; }

0 commit comments

Comments
 (0)