@@ -221,6 +221,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
221
221
extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
222
222
typeAliasDecl;
223
223
224
+ // / \brief Matches shadow declarations introduced into a scope by a
225
+ // / (resolved) using declaration.
226
+ // /
227
+ // / Given
228
+ // / \code
229
+ // / namespace n { int f; }
230
+ // / namespace declToImport { using n::f; }
231
+ // / \endcode
232
+ // / usingShadowDecl()
233
+ // / matches \code f \endcode
234
+ extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
235
+ usingShadowDecl;
236
+
224
237
// / Matches type alias template declarations.
225
238
// /
226
239
// / typeAliasTemplateDecl() matches
@@ -3718,7 +3731,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
3718
3731
// / Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
3719
3732
// / Matcher<TagType>, Matcher<TemplateSpecializationType>,
3720
3733
// / Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
3721
- // / Matcher<UnresolvedUsingType>
3734
+ // / Matcher<UnresolvedUsingType>, Matcher<UsingType>
3722
3735
inline internal::PolymorphicMatcher<
3723
3736
internal::HasDeclarationMatcher,
3724
3737
void (internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4353,7 +4366,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
4353
4366
AST_POLYMORPHIC_SUPPORTED_TYPES (DeclRefExpr,
4354
4367
UsingType),
4355
4368
internal::Matcher<UsingShadowDecl>, Inner) {
4356
- const NamedDecl *FoundDecl = Node.getFoundDecl ();
4369
+ const NamedDecl *FoundDecl;
4370
+ if constexpr (std::is_same_v<NodeType, UsingType>) {
4371
+ FoundDecl = Node.getDecl ();
4372
+ } else {
4373
+ static_assert (std::is_same_v<NodeType, DeclRefExpr>);
4374
+ FoundDecl = Node.getFoundDecl ();
4375
+ }
4357
4376
if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
4358
4377
return Inner.matches (*UsingDecl, Finder, Builder);
4359
4378
return false ;
@@ -6982,37 +7001,6 @@ AST_POLYMORPHIC_MATCHER_P2(
6982
7001
InnerMatcher.matches (Args[Index], Finder, Builder);
6983
7002
}
6984
7003
6985
- // / Matches C or C++ elaborated `TypeLoc`s.
6986
- // /
6987
- // / Given
6988
- // / \code
6989
- // / struct s {};
6990
- // / struct s ss;
6991
- // / \endcode
6992
- // / elaboratedTypeLoc()
6993
- // / matches the `TypeLoc` of the variable declaration of `ss`.
6994
- extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
6995
- elaboratedTypeLoc;
6996
-
6997
- // / Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
6998
- // / `InnerMatcher`.
6999
- // /
7000
- // / Given
7001
- // / \code
7002
- // / template <typename T>
7003
- // / class C {};
7004
- // / class C<int> c;
7005
- // /
7006
- // / class D {};
7007
- // / class D d;
7008
- // / \endcode
7009
- // / elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
7010
- // / matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
7011
- AST_MATCHER_P (ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
7012
- InnerMatcher) {
7013
- return InnerMatcher.matches (Node.getNamedTypeLoc (), Finder, Builder);
7014
- }
7015
-
7016
7004
// / Matches type \c bool.
7017
7005
// /
7018
7006
// / Given
@@ -7279,7 +7267,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
7279
7267
AST_TYPE_TRAVERSE_MATCHER (hasDeducedType, getDeducedType,
7280
7268
AST_POLYMORPHIC_SUPPORTED_TYPES (AutoType));
7281
7269
7282
- // / Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
7270
+ // / Matches \c QualType nodes to find the underlying type.
7283
7271
// /
7284
7272
// / Given
7285
7273
// / \code
@@ -7289,10 +7277,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
7289
7277
// / decltypeType(hasUnderlyingType(isInteger()))
7290
7278
// / matches the type of "a"
7291
7279
// /
7292
- // / Usable as: Matcher<DecltypeType>, Matcher<UsingType>
7293
- AST_TYPE_TRAVERSE_MATCHER (hasUnderlyingType, getUnderlyingType,
7294
- AST_POLYMORPHIC_SUPPORTED_TYPES (DecltypeType,
7295
- UsingType));
7280
+ // / Usable as: Matcher<QualType>
7281
+ AST_MATCHER_P (Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
7282
+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType ();
7283
+ if (QT == QualType (&Node, 0 ))
7284
+ return false ;
7285
+ return Inner.matches (QT, Finder, Builder);
7286
+ }
7296
7287
7297
7288
// / Matches \c FunctionType nodes.
7298
7289
// /
@@ -7571,27 +7562,7 @@ extern const AstTypeMatcher<RecordType> recordType;
7571
7562
// / and \c c.
7572
7563
extern const AstTypeMatcher<TagType> tagType;
7573
7564
7574
- // / Matches types specified with an elaborated type keyword or with a
7575
- // / qualified name.
7576
- // /
7577
- // / Given
7578
- // / \code
7579
- // / namespace N {
7580
- // / namespace M {
7581
- // / class D {};
7582
- // / }
7583
- // / }
7584
- // / class C {};
7585
- // /
7586
- // / class C c;
7587
- // / N::M::D d;
7588
- // / \endcode
7589
- // /
7590
- // / \c elaboratedType() matches the type of the variable declarations of both
7591
- // / \c c and \c d.
7592
- extern const AstTypeMatcher<ElaboratedType> elaboratedType;
7593
-
7594
- // / Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
7565
+ // / Matches Types whose qualifier, a NestedNameSpecifier,
7595
7566
// / matches \c InnerMatcher if the qualifier exists.
7596
7567
// /
7597
7568
// / Given
@@ -7606,34 +7577,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
7606
7577
// /
7607
7578
// / \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
7608
7579
// / matches the type of the variable declaration of \c d.
7609
- AST_MATCHER_P (ElaboratedType , hasQualifier,
7610
- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
7611
- if (const NestedNameSpecifier * Qualifier = Node.getQualifier ())
7612
- return InnerMatcher.matches (* Qualifier, Finder, Builder);
7580
+ AST_MATCHER_P (Type , hasQualifier, internal::Matcher<NestedNameSpecifier> ,
7581
+ InnerMatcher) {
7582
+ if (NestedNameSpecifier Qualifier = Node.getPrefix ())
7583
+ return InnerMatcher.matches (Qualifier, Finder, Builder);
7613
7584
7614
7585
return false ;
7615
7586
}
7616
7587
7617
- // / Matches ElaboratedTypes whose named type matches \c InnerMatcher.
7618
- // /
7619
- // / Given
7620
- // / \code
7621
- // / namespace N {
7622
- // / namespace M {
7623
- // / class D {};
7624
- // / }
7625
- // / }
7626
- // / N::M::D d;
7627
- // / \endcode
7628
- // /
7629
- // / \c elaboratedType(namesType(recordType(
7630
- // / hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
7631
- // / declaration of \c d.
7632
- AST_MATCHER_P (ElaboratedType, namesType, internal::Matcher<QualType>,
7633
- InnerMatcher) {
7634
- return InnerMatcher.matches (Node.getNamedType (), Finder, Builder);
7635
- }
7636
-
7637
7588
// / Matches types specified through a using declaration.
7638
7589
// /
7639
7590
// / Given
@@ -7802,7 +7753,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
7802
7753
// / matches "A::"
7803
7754
AST_MATCHER_P (NestedNameSpecifier, specifiesType,
7804
7755
internal::Matcher<QualType>, InnerMatcher) {
7805
- if (! Node.getAsType () )
7756
+ if (Node.getKind () != NestedNameSpecifier::Kind::Type )
7806
7757
return false ;
7807
7758
return InnerMatcher.matches (QualType (Node.getAsType (), 0 ), Finder, Builder);
7808
7759
}
@@ -7820,8 +7771,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
7820
7771
// / matches "A::"
7821
7772
AST_MATCHER_P (NestedNameSpecifierLoc, specifiesTypeLoc,
7822
7773
internal::Matcher<TypeLoc>, InnerMatcher) {
7823
- return Node && Node.getNestedNameSpecifier ()->getAsType () &&
7824
- InnerMatcher.matches (Node.getTypeLoc (), Finder, Builder);
7774
+ if (!Node)
7775
+ return false ;
7776
+ TypeLoc TL = Node.getAsTypeLoc ();
7777
+ if (!TL)
7778
+ return false ;
7779
+ return InnerMatcher.matches (TL, Finder, Builder);
7825
7780
}
7826
7781
7827
7782
// / Matches on the prefix of a \c NestedNameSpecifier.
@@ -7836,10 +7791,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
7836
7791
AST_MATCHER_P_OVERLOAD (NestedNameSpecifier, hasPrefix,
7837
7792
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
7838
7793
0 ) {
7839
- const NestedNameSpecifier *NextNode = Node.getPrefix ();
7794
+ NestedNameSpecifier NextNode = std::nullopt;
7795
+ switch (Node.getKind ()) {
7796
+ case NestedNameSpecifier::Kind::Namespace:
7797
+ NextNode = Node.getAsNamespaceAndPrefix ().Prefix ;
7798
+ break ;
7799
+ case NestedNameSpecifier::Kind::Type:
7800
+ NextNode = Node.getAsType ()->getPrefix ();
7801
+ break ;
7802
+ default :
7803
+ break ;
7804
+ }
7805
+
7840
7806
if (!NextNode)
7841
7807
return false ;
7842
- return InnerMatcher.matches (* NextNode, Finder, Builder);
7808
+ return InnerMatcher.matches (NextNode, Finder, Builder);
7843
7809
}
7844
7810
7845
7811
// / Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7854,7 +7820,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
7854
7820
AST_MATCHER_P_OVERLOAD (NestedNameSpecifierLoc, hasPrefix,
7855
7821
internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
7856
7822
1 ) {
7857
- NestedNameSpecifierLoc NextNode = Node.getPrefix ();
7823
+ NestedNameSpecifierLoc NextNode;
7824
+ if (TypeLoc TL = Node.getAsTypeLoc ())
7825
+ NextNode = TL.getPrefix ();
7826
+ else
7827
+ NextNode = Node.getAsNamespaceAndPrefix ().Prefix ;
7828
+
7858
7829
if (!NextNode)
7859
7830
return false ;
7860
7831
return InnerMatcher.matches (NextNode, Finder, Builder);
@@ -7872,9 +7843,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
7872
7843
// / matches "ns::"
7873
7844
AST_MATCHER_P (NestedNameSpecifier, specifiesNamespace,
7874
7845
internal::Matcher<NamespaceDecl>, InnerMatcher) {
7875
- if (!Node.getAsNamespace ())
7846
+ if (Node.getKind () != NestedNameSpecifier::Kind::Namespace)
7847
+ return false ;
7848
+ const auto *Namespace =
7849
+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix ().Namespace );
7850
+ if (!Namespace)
7876
7851
return false ;
7877
- return InnerMatcher.matches (*Node. getAsNamespace () , Finder, Builder);
7852
+ return InnerMatcher.matches (*Namespace , Finder, Builder);
7878
7853
}
7879
7854
7880
7855
// / Matches attributes.
0 commit comments