Skip to content

Commit 168ea81

Browse files
committed
[FOLD]
1 parent 0834af0 commit 168ea81

File tree

2 files changed

+53
-59
lines changed

2 files changed

+53
-59
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,21 @@ class BuiltinTemplateDecl : public TemplateDecl {
17601760
BuiltinTemplateKind getBuiltinTemplateKind() const { return BTK; }
17611761
};
17621762

1763+
/// Provides information about an explicit instantiation of a variable or class
1764+
/// template.
1765+
struct ExplicitInstantiationInfo {
1766+
/// The template arguments as written..
1767+
const ASTTemplateArgumentListInfo *TemplateArgsAsWritten = nullptr;
1768+
1769+
/// The location of the extern keyword.
1770+
SourceLocation ExternLoc;
1771+
1772+
/// The location of the template keyword.
1773+
SourceLocation TemplateKeywordLoc;
1774+
1775+
ExplicitInstantiationInfo() = default;
1776+
};
1777+
17631778
/// Represents a class template specialization, which refers to
17641779
/// a class template with a given set of template arguments.
17651780
///
@@ -1792,19 +1807,6 @@ class ClassTemplateSpecializationDecl
17921807
llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *>
17931808
SpecializedTemplate;
17941809

1795-
struct ExplicitInstantiationInfo {
1796-
/// The template arguments as written..
1797-
const ASTTemplateArgumentListInfo *TemplateArgsAsWritten = nullptr;
1798-
1799-
/// The location of the extern keyword.
1800-
SourceLocation ExternLoc;
1801-
1802-
/// The location of the template keyword.
1803-
SourceLocation TemplateKeywordLoc;
1804-
1805-
ExplicitInstantiationInfo() = default;
1806-
};
1807-
18081810
/// Further info for explicit template specialization/instantiation.
18091811
/// Does not apply to implicit specializations.
18101812
llvm::PointerUnion<const ASTTemplateArgumentListInfo *,
@@ -1986,26 +1988,15 @@ class ClassTemplateSpecializationDecl
19861988
SpecializedTemplate = TemplDecl;
19871989
}
19881990

1991+
/// Retrieve the template argument list as written in the sources,
1992+
/// if any.
19891993
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
19901994
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
19911995
return Info->TemplateArgsAsWritten;
19921996
return ExplicitInfo.get<const ASTTemplateArgumentListInfo *>();
19931997
}
19941998

1995-
/// Gets the location of the extern keyword, if present.
1996-
SourceLocation getExternLoc() const {
1997-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
1998-
return Info->ExternLoc;
1999-
return SourceLocation();
2000-
}
2001-
2002-
/// Gets the location of the template keyword, if present.
2003-
SourceLocation getTemplateKeywordLoc() const {
2004-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2005-
return Info->TemplateKeywordLoc;
2006-
return SourceLocation();
2007-
}
2008-
1999+
/// Set the template argument list as written in the sources.
20092000
void
20102001
setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten) {
20112002
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
@@ -2014,14 +2005,29 @@ class ClassTemplateSpecializationDecl
20142005
ExplicitInfo = ArgsWritten;
20152006
}
20162007

2008+
/// Set the template argument list as written in the sources.
20172009
void setTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgsInfo) {
20182010
setTemplateArgsAsWritten(
20192011
ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo));
20202012
}
20212013

2014+
/// Gets the location of the extern keyword, if present.
2015+
SourceLocation getExternLoc() const {
2016+
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2017+
return Info->ExternLoc;
2018+
return SourceLocation();
2019+
}
2020+
20222021
/// Sets the location of the extern keyword.
20232022
void setExternLoc(SourceLocation Loc);
20242023

2024+
/// Gets the location of the template keyword, if present.
2025+
SourceLocation getTemplateKeywordLoc() const {
2026+
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2027+
return Info->TemplateKeywordLoc;
2028+
return SourceLocation();
2029+
}
2030+
20252031
/// Sets the location of the template keyword.
20262032
void setTemplateKeywordLoc(SourceLocation Loc);
20272033

@@ -2582,19 +2588,6 @@ class VarTemplateSpecializationDecl : public VarDecl,
25822588
llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *>
25832589
SpecializedTemplate;
25842590

2585-
struct ExplicitInstantiationInfo {
2586-
/// The template arguments as written..
2587-
const ASTTemplateArgumentListInfo *TemplateArgsAsWritten = nullptr;
2588-
2589-
/// The location of the extern keyword.
2590-
SourceLocation ExternLoc;
2591-
2592-
/// The location of the template keyword.
2593-
SourceLocation TemplateKeywordLoc;
2594-
2595-
ExplicitInstantiationInfo() = default;
2596-
};
2597-
25982591
/// Further info for explicit template specialization/instantiation.
25992592
/// Does not apply to implicit specializations.
26002593
llvm::PointerUnion<const ASTTemplateArgumentListInfo *,
@@ -2603,7 +2596,6 @@ class VarTemplateSpecializationDecl : public VarDecl,
26032596

26042597
/// The template arguments used to describe this specialization.
26052598
const TemplateArgumentList *TemplateArgs;
2606-
const ASTTemplateArgumentListInfo *TemplateArgsInfo = nullptr;
26072599

26082600
/// The point where this template was instantiated (if any).
26092601
SourceLocation PointOfInstantiation;
@@ -2760,26 +2752,15 @@ class VarTemplateSpecializationDecl : public VarDecl,
27602752
SpecializedTemplate = TemplDecl;
27612753
}
27622754

2755+
/// Retrieve the template argument list as written in the sources,
2756+
/// if any.
27632757
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
27642758
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
27652759
return Info->TemplateArgsAsWritten;
27662760
return ExplicitInfo.get<const ASTTemplateArgumentListInfo *>();
27672761
}
27682762

2769-
/// Gets the location of the extern keyword, if present.
2770-
SourceLocation getExternLoc() const {
2771-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2772-
return Info->ExternLoc;
2773-
return SourceLocation();
2774-
}
2775-
2776-
/// Gets the location of the template keyword, if present.
2777-
SourceLocation getTemplateKeywordLoc() const {
2778-
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2779-
return Info->TemplateKeywordLoc;
2780-
return SourceLocation();
2781-
}
2782-
2763+
/// Set the template argument list as written in the sources.
27832764
void
27842765
setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten) {
27852766
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
@@ -2788,14 +2769,29 @@ class VarTemplateSpecializationDecl : public VarDecl,
27882769
ExplicitInfo = ArgsWritten;
27892770
}
27902771

2772+
/// Set the template argument list as written in the sources.
27912773
void setTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgsInfo) {
27922774
setTemplateArgsAsWritten(
27932775
ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo));
27942776
}
27952777

2778+
/// Gets the location of the extern keyword, if present.
2779+
SourceLocation getExternLoc() const {
2780+
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2781+
return Info->ExternLoc;
2782+
return SourceLocation();
2783+
}
2784+
27962785
/// Sets the location of the extern keyword.
27972786
void setExternLoc(SourceLocation Loc);
27982787

2788+
/// Gets the location of the template keyword, if present.
2789+
SourceLocation getTemplateKeywordLoc() const {
2790+
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2791+
return Info->TemplateKeywordLoc;
2792+
return SourceLocation();
2793+
}
2794+
27992795
/// Sets the location of the template keyword.
28002796
void setTemplateKeywordLoc(SourceLocation Loc);
28012797

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,8 +2548,7 @@ ASTDeclReader::VisitClassTemplateSpecializationDeclImpl(
25482548
if (Record.readBool()) {
25492549
// FIXME: We don't need to allocate this if ExternLoc and TemplateKeywordLoc
25502550
// are invalid!
2551-
auto *ExplicitInfo =
2552-
new (C) ClassTemplateSpecializationDecl::ExplicitInstantiationInfo;
2551+
auto *ExplicitInfo = new (C) ExplicitInstantiationInfo;
25532552
ExplicitInfo->TemplateArgsAsWritten =
25542553
Record.readASTTemplateArgumentListInfo();
25552554
ExplicitInfo->ExternLoc = readSourceLocation();
@@ -2619,8 +2618,7 @@ ASTDeclReader::VisitVarTemplateSpecializationDeclImpl(
26192618
if (Record.readBool()) {
26202619
// FIXME: We don't need to allocate this if ExternLoc and TemplateKeywordLoc
26212620
// are invalid!
2622-
auto *ExplicitInfo =
2623-
new (C) VarTemplateSpecializationDecl::ExplicitInstantiationInfo;
2621+
auto *ExplicitInfo = new (C) ExplicitInstantiationInfo;
26242622
ExplicitInfo->TemplateArgsAsWritten =
26252623
Record.readASTTemplateArgumentListInfo();
26262624
ExplicitInfo->ExternLoc = readSourceLocation();

0 commit comments

Comments
 (0)