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