Skip to content

Commit 6e31920

Browse files
committed
[clang] improved preservation of template keyword
This makes it so clang can better represent the abscence of the template keyword for a template which cannot be resolved due to a dependent prefix. The tracking of the template keyword is removed from the NestedNameSpecifier, and added to the last type node which had it missing, the DependentTemplateSpecializationType (DTST). The DTST and the DependentTemplateName are refactored to share most of their implementation. That refactoring along with the removal of the TypeSpecWithTemplate kind from the nested name specifiers amounts to a large amount of code removed, making this patch a small performance improvement overall. This will also enable future further simplifications. As a drive-by, this removes some special cases from the type printer, allowing template arguments within NestedNameSpecifiers to not have their nested names suppressed when printing.
1 parent 7db83f2 commit 6e31920

File tree

66 files changed

+612
-720
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+612
-720
lines changed

clang-tools-extra/clangd/AST.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ getQualification(ASTContext &Context, const DeclContext *DestContext,
119119
// There can't be any more tag parents after hitting a namespace.
120120
assert(!ReachedNS);
121121
(void)ReachedNS;
122-
NNS = NestedNameSpecifier::Create(Context, nullptr, false,
123-
TD->getTypeForDecl());
122+
NNS = NestedNameSpecifier::Create(Context, nullptr, TD->getTypeForDecl());
124123
} else if (auto *NSD = llvm::dyn_cast<NamespaceDecl>(CurContext)) {
125124
ReachedNS = true;
126125
NNS = NestedNameSpecifier::Create(Context, nullptr, NSD);

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,6 @@ bool allowIndex(CodeCompletionContext &CC) {
14671467
return true;
14681468
case NestedNameSpecifier::Super:
14691469
case NestedNameSpecifier::TypeSpec:
1470-
case NestedNameSpecifier::TypeSpecWithTemplate:
14711470
// Unresolved inside a template.
14721471
case NestedNameSpecifier::Identifier:
14731472
return false;

clang-tools-extra/clangd/DumpAST.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
157157
NNS_KIND(Identifier);
158158
NNS_KIND(Namespace);
159159
NNS_KIND(TypeSpec);
160-
NNS_KIND(TypeSpecWithTemplate);
161160
NNS_KIND(Global);
162161
NNS_KIND(Super);
163162
NNS_KIND(NamespaceAlias);

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ struct TargetFinder {
500500
}
501501
return;
502502
case NestedNameSpecifier::TypeSpec:
503-
case NestedNameSpecifier::TypeSpecWithTemplate:
504503
add(QualType(NNS->getAsType(), 0), Flags);
505504
return;
506505
case NestedNameSpecifier::Global:

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
144144
case NestedNameSpecifier::Global:
145145
return true;
146146
case NestedNameSpecifier::TypeSpec:
147-
case NestedNameSpecifier::TypeSpecWithTemplate:
148147
case NestedNameSpecifier::Super:
149148
case NestedNameSpecifier::Identifier:
150149
return false;

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ Improvements to Clang's diagnostics
275275
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
276276
``-Wno-error=parentheses``.
277277
- Clang now better preserves the sugared types of pointers to member.
278+
- Clang now better preserves the presence of the template keyword with dependent
279+
prefixes.
280+
- When printing types for diagnostics, clang now doesn't suppress the scopes of
281+
template arguments contained within nested names.
278282
- The ``-Wshift-bool`` warning has been added to warn about shifting a boolean. (#GH28334)
279283
- Fixed diagnostics adding a trailing ``::`` when printing some source code
280284
constructs, like base classes.

clang/include/clang/AST/ASTContext.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,15 +1835,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
18351835
TagDecl *OwnedTagDecl = nullptr) const;
18361836
QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
18371837
NestedNameSpecifier *NNS,
1838-
const IdentifierInfo *Name,
1839-
QualType Canon = QualType()) const;
1838+
const IdentifierInfo *Name) const;
18401839

18411840
QualType getDependentTemplateSpecializationType(
1842-
ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
1843-
const IdentifierInfo *Name, ArrayRef<TemplateArgumentLoc> Args) const;
1841+
ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &Name,
1842+
ArrayRef<TemplateArgumentLoc> Args) const;
18441843
QualType getDependentTemplateSpecializationType(
1845-
ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
1846-
const IdentifierInfo *Name, ArrayRef<TemplateArgument> Args) const;
1844+
ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &Name,
1845+
ArrayRef<TemplateArgument> Args, bool IsCanonical = false) const;
18471846

18481847
TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl) const;
18491848

@@ -2392,10 +2391,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
23922391
bool TemplateKeyword,
23932392
TemplateName Template) const;
23942393

2395-
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
2396-
const IdentifierInfo *Name) const;
2397-
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
2398-
OverloadedOperatorKind Operator) const;
2394+
TemplateName
2395+
getDependentTemplateName(const DependentTemplateStorage &Name) const;
23992396
TemplateName getSubstTemplateTemplateParm(TemplateName replacement,
24002397
Decl *AssociatedDecl,
24012398
unsigned Index,

clang/include/clang/AST/ASTImporter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,14 @@ class TypeSourceInfo;
446446
/// returns nullptr only if the FromId was nullptr.
447447
IdentifierInfo *Import(const IdentifierInfo *FromId);
448448

449+
/// Import the given identifier or overloaded operator from the "from"
450+
/// context into the "to" context.
451+
///
452+
/// \returns The equivalent identifier or overloaded operator in the "to"
453+
/// context.
454+
IdentifierOrOverloadedOperator
455+
Import(IdentifierOrOverloadedOperator FromIO);
456+
449457
/// Import the given Objective-C selector from the "from"
450458
/// context into the "to" context.
451459
///

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ class ASTNodeTraverser
396396
// FIXME: Provide a NestedNameSpecifier visitor.
397397
NestedNameSpecifier *Qualifier = T->getQualifier();
398398
if (NestedNameSpecifier::SpecifierKind K = Qualifier->getKind();
399-
K == NestedNameSpecifier::TypeSpec ||
400-
K == NestedNameSpecifier::TypeSpecWithTemplate)
399+
K == NestedNameSpecifier::TypeSpec)
401400
Visit(Qualifier->getAsType());
402401
if (T->isSugared())
403402
Visit(T->getMostRecentCXXRecordDecl()->getTypeForDecl());

clang/include/clang/AST/AbstractBasicReader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,8 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
279279
continue;
280280

281281
case NestedNameSpecifier::TypeSpec:
282-
case NestedNameSpecifier::TypeSpecWithTemplate:
283282
cur = NestedNameSpecifier::Create(ctx, cur,
284-
kind == NestedNameSpecifier::TypeSpecWithTemplate,
285-
asImpl().readQualType().getTypePtr());
283+
asImpl().readQualType().getTypePtr());
286284
continue;
287285

288286
case NestedNameSpecifier::Global:

0 commit comments

Comments
 (0)