@@ -222,6 +222,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
222
222
extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
223
223
typeAliasDecl;
224
224
225
+ // / \brief Matches shadow declarations introduced into a scope by a
226
+ // / (resolved) using declaration.
227
+ // /
228
+ // / Given
229
+ // / \code
230
+ // / namespace n { int f; }
231
+ // / namespace declToImport { using n::f; }
232
+ // / \endcode
233
+ // / usingShadowDecl()
234
+ // / matches \code f \endcode
235
+ extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
236
+ usingShadowDecl;
237
+
225
238
// / Matches type alias template declarations.
226
239
// /
227
240
// / typeAliasTemplateDecl() matches
@@ -3739,7 +3752,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
3739
3752
// / Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
3740
3753
// / Matcher<TagType>, Matcher<TemplateSpecializationType>,
3741
3754
// / Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
3742
- // / Matcher<UnresolvedUsingType>
3755
+ // / Matcher<UnresolvedUsingType>, Matcher<UsingType>
3743
3756
inline internal::PolymorphicMatcher<
3744
3757
internal::HasDeclarationMatcher,
3745
3758
void (internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4374,7 +4387,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
4374
4387
AST_POLYMORPHIC_SUPPORTED_TYPES (DeclRefExpr,
4375
4388
UsingType),
4376
4389
internal::Matcher<UsingShadowDecl>, Inner) {
4377
- const NamedDecl *FoundDecl = Node.getFoundDecl ();
4390
+ const NamedDecl *FoundDecl;
4391
+ if constexpr (std::is_same_v<NodeType, UsingType>) {
4392
+ FoundDecl = Node.getDecl ();
4393
+ } else {
4394
+ static_assert (std::is_same_v<NodeType, DeclRefExpr>);
4395
+ FoundDecl = Node.getFoundDecl ();
4396
+ }
4378
4397
if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
4379
4398
return Inner.matches (*UsingDecl, Finder, Builder);
4380
4399
return false ;
@@ -7003,37 +7022,6 @@ AST_POLYMORPHIC_MATCHER_P2(
7003
7022
InnerMatcher.matches (Args[Index], Finder, Builder);
7004
7023
}
7005
7024
7006
- // / Matches C or C++ elaborated `TypeLoc`s.
7007
- // /
7008
- // / Given
7009
- // / \code
7010
- // / struct s {};
7011
- // / struct s ss;
7012
- // / \endcode
7013
- // / elaboratedTypeLoc()
7014
- // / matches the `TypeLoc` of the variable declaration of `ss`.
7015
- extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
7016
- elaboratedTypeLoc;
7017
-
7018
- // / Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
7019
- // / `InnerMatcher`.
7020
- // /
7021
- // / Given
7022
- // / \code
7023
- // / template <typename T>
7024
- // / class C {};
7025
- // / class C<int> c;
7026
- // /
7027
- // / class D {};
7028
- // / class D d;
7029
- // / \endcode
7030
- // / elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
7031
- // / matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
7032
- AST_MATCHER_P (ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
7033
- InnerMatcher) {
7034
- return InnerMatcher.matches (Node.getNamedTypeLoc (), Finder, Builder);
7035
- }
7036
-
7037
7025
// / Matches type \c bool.
7038
7026
// /
7039
7027
// / Given
@@ -7300,7 +7288,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
7300
7288
AST_TYPE_TRAVERSE_MATCHER (hasDeducedType, getDeducedType,
7301
7289
AST_POLYMORPHIC_SUPPORTED_TYPES (AutoType));
7302
7290
7303
- // / Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
7291
+ // / Matches \c QualType nodes to find the underlying type.
7304
7292
// /
7305
7293
// / Given
7306
7294
// / \code
@@ -7310,10 +7298,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
7310
7298
// / decltypeType(hasUnderlyingType(isInteger()))
7311
7299
// / matches the type of "a"
7312
7300
// /
7313
- // / Usable as: Matcher<DecltypeType>, Matcher<UsingType>
7314
- AST_TYPE_TRAVERSE_MATCHER (hasUnderlyingType, getUnderlyingType,
7315
- AST_POLYMORPHIC_SUPPORTED_TYPES (DecltypeType,
7316
- UsingType));
7301
+ // / Usable as: Matcher<QualType>
7302
+ AST_MATCHER_P (Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
7303
+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType ();
7304
+ if (QT == QualType (&Node, 0 ))
7305
+ return false ;
7306
+ return Inner.matches (QT, Finder, Builder);
7307
+ }
7317
7308
7318
7309
// / Matches \c FunctionType nodes.
7319
7310
// /
@@ -7592,27 +7583,7 @@ extern const AstTypeMatcher<RecordType> recordType;
7592
7583
// / and \c c.
7593
7584
extern const AstTypeMatcher<TagType> tagType;
7594
7585
7595
- // / Matches types specified with an elaborated type keyword or with a
7596
- // / qualified name.
7597
- // /
7598
- // / Given
7599
- // / \code
7600
- // / namespace N {
7601
- // / namespace M {
7602
- // / class D {};
7603
- // / }
7604
- // / }
7605
- // / class C {};
7606
- // /
7607
- // / class C c;
7608
- // / N::M::D d;
7609
- // / \endcode
7610
- // /
7611
- // / \c elaboratedType() matches the type of the variable declarations of both
7612
- // / \c c and \c d.
7613
- extern const AstTypeMatcher<ElaboratedType> elaboratedType;
7614
-
7615
- // / Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
7586
+ // / Matches Types whose qualifier, a NestedNameSpecifier,
7616
7587
// / matches \c InnerMatcher if the qualifier exists.
7617
7588
// /
7618
7589
// / Given
@@ -7627,34 +7598,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
7627
7598
// /
7628
7599
// / \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
7629
7600
// / matches the type of the variable declaration of \c d.
7630
- AST_MATCHER_P (ElaboratedType , hasQualifier,
7631
- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
7632
- if (const NestedNameSpecifier * Qualifier = Node.getQualifier ())
7633
- return InnerMatcher.matches (* Qualifier, Finder, Builder);
7601
+ AST_MATCHER_P (Type , hasQualifier, internal::Matcher<NestedNameSpecifier> ,
7602
+ InnerMatcher) {
7603
+ if (NestedNameSpecifier Qualifier = Node.getPrefix ())
7604
+ return InnerMatcher.matches (Qualifier, Finder, Builder);
7634
7605
7635
7606
return false ;
7636
7607
}
7637
7608
7638
- // / Matches ElaboratedTypes whose named type matches \c InnerMatcher.
7639
- // /
7640
- // / Given
7641
- // / \code
7642
- // / namespace N {
7643
- // / namespace M {
7644
- // / class D {};
7645
- // / }
7646
- // / }
7647
- // / N::M::D d;
7648
- // / \endcode
7649
- // /
7650
- // / \c elaboratedType(namesType(recordType(
7651
- // / hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
7652
- // / declaration of \c d.
7653
- AST_MATCHER_P (ElaboratedType, namesType, internal::Matcher<QualType>,
7654
- InnerMatcher) {
7655
- return InnerMatcher.matches (Node.getNamedType (), Finder, Builder);
7656
- }
7657
-
7658
7609
// / Matches types specified through a using declaration.
7659
7610
// /
7660
7611
// / Given
@@ -7823,7 +7774,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
7823
7774
// / matches "A::"
7824
7775
AST_MATCHER_P (NestedNameSpecifier, specifiesType,
7825
7776
internal::Matcher<QualType>, InnerMatcher) {
7826
- if (! Node.getAsType () )
7777
+ if (Node.getKind () != NestedNameSpecifier::Kind::Type )
7827
7778
return false ;
7828
7779
return InnerMatcher.matches (QualType (Node.getAsType (), 0 ), Finder, Builder);
7829
7780
}
@@ -7841,8 +7792,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
7841
7792
// / matches "A::"
7842
7793
AST_MATCHER_P (NestedNameSpecifierLoc, specifiesTypeLoc,
7843
7794
internal::Matcher<TypeLoc>, InnerMatcher) {
7844
- return Node && Node.getNestedNameSpecifier ()->getAsType () &&
7845
- InnerMatcher.matches (Node.getTypeLoc (), Finder, Builder);
7795
+ if (!Node)
7796
+ return false ;
7797
+ TypeLoc TL = Node.getAsTypeLoc ();
7798
+ if (!TL)
7799
+ return false ;
7800
+ return InnerMatcher.matches (TL, Finder, Builder);
7846
7801
}
7847
7802
7848
7803
// / Matches on the prefix of a \c NestedNameSpecifier.
@@ -7857,10 +7812,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
7857
7812
AST_MATCHER_P_OVERLOAD (NestedNameSpecifier, hasPrefix,
7858
7813
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
7859
7814
0 ) {
7860
- const NestedNameSpecifier *NextNode = Node.getPrefix ();
7815
+ NestedNameSpecifier NextNode = std::nullopt;
7816
+ switch (Node.getKind ()) {
7817
+ case NestedNameSpecifier::Kind::Namespace:
7818
+ NextNode = Node.getAsNamespaceAndPrefix ().Prefix ;
7819
+ break ;
7820
+ case NestedNameSpecifier::Kind::Type:
7821
+ NextNode = Node.getAsType ()->getPrefix ();
7822
+ break ;
7823
+ default :
7824
+ break ;
7825
+ }
7826
+
7861
7827
if (!NextNode)
7862
7828
return false ;
7863
- return InnerMatcher.matches (* NextNode, Finder, Builder);
7829
+ return InnerMatcher.matches (NextNode, Finder, Builder);
7864
7830
}
7865
7831
7866
7832
// / Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7875,7 +7841,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
7875
7841
AST_MATCHER_P_OVERLOAD (NestedNameSpecifierLoc, hasPrefix,
7876
7842
internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
7877
7843
1 ) {
7878
- NestedNameSpecifierLoc NextNode = Node.getPrefix ();
7844
+ NestedNameSpecifierLoc NextNode;
7845
+ if (TypeLoc TL = Node.getAsTypeLoc ())
7846
+ NextNode = TL.getPrefix ();
7847
+ else
7848
+ NextNode = Node.getAsNamespaceAndPrefix ().Prefix ;
7849
+
7879
7850
if (!NextNode)
7880
7851
return false ;
7881
7852
return InnerMatcher.matches (NextNode, Finder, Builder);
@@ -7893,9 +7864,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
7893
7864
// / matches "ns::"
7894
7865
AST_MATCHER_P (NestedNameSpecifier, specifiesNamespace,
7895
7866
internal::Matcher<NamespaceDecl>, InnerMatcher) {
7896
- if (!Node.getAsNamespace ())
7867
+ if (Node.getKind () != NestedNameSpecifier::Kind::Namespace)
7868
+ return false ;
7869
+ const auto *Namespace =
7870
+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix ().Namespace );
7871
+ if (!Namespace)
7897
7872
return false ;
7898
- return InnerMatcher.matches (*Node. getAsNamespace () , Finder, Builder);
7873
+ return InnerMatcher.matches (*Namespace , Finder, Builder);
7899
7874
}
7900
7875
7901
7876
// / Matches attributes.
0 commit comments