Skip to content

Commit 1f57ee7

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 f5c47fb commit 1f57ee7

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
@@ -1112,6 +1112,20 @@ class FunctionTemplateDecl : public RedeclarableTemplateDecl {
11121112
return makeSpecIterator(getSpecializations(), true);
11131113
}
11141114

1115+
/// All specializations that that have already been loaded, ie avoiding
1116+
/// deserialization of lazily registered specializations.
1117+
spec_range loaded_specializations() const {
1118+
return spec_range(loaded_spec_begin(), loaded_spec_end());
1119+
}
1120+
1121+
spec_iterator loaded_spec_begin() const {
1122+
return makeSpecIterator(getCommonPtr()->Specializations, false);
1123+
}
1124+
1125+
spec_iterator loaded_spec_end() const {
1126+
return makeSpecIterator(getCommonPtr()->Specializations, true);
1127+
}
1128+
11151129
/// Return whether this function template is an abbreviated function template,
11161130
/// e.g. `void foo(auto x)` or `template<typename T> void foo(auto x)`
11171131
bool isAbbreviated() const {
@@ -2446,6 +2460,20 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
24462460
return makeSpecIterator(getSpecializations(), true);
24472461
}
24482462

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

3297+
/// All specializations that that have already been loaded, ie avoiding
3298+
/// deserialization of lazily registered specializations.
3299+
spec_range loaded_specializations() const {
3300+
return spec_range(loaded_spec_begin(), loaded_spec_end());
3301+
}
3302+
3303+
spec_iterator loaded_spec_begin() const {
3304+
return makeSpecIterator(getCommonPtr()->Specializations, false);
3305+
}
3306+
3307+
spec_iterator loaded_spec_end() const {
3308+
return makeSpecIterator(getCommonPtr()->Specializations, true);
3309+
}
3310+
32693311
// Implement isa/cast/dyncast support
32703312
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
32713313
static bool classofKind(Kind K) { return K == VarTemplate; }

0 commit comments

Comments
 (0)