[PATCH] D48759: [ASTMatchers] add matcher for decltypeType and its underlyingType

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 29 03:01:15 PDT 2018


JonasToth created this revision.
JonasToth added reviewers: aaron.ballman, alexfh, NoQ, dcoughlin.
Herald added a subscriber: cfe-commits.

This patch introduces a new matcher for `DecltypeType` and its underlying type
in order to fix a bug in clang-tidy, see https://reviews.llvm.org/D48717 for more.


Repository:
  rC Clang

https://reviews.llvm.org/D48759

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/ASTMatchersInternal.cpp
  lib/ASTMatchers/Dynamic/Registry.cpp


Index: lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -134,6 +134,7 @@
   REGISTER_MATCHER(atomicExpr);
   REGISTER_MATCHER(atomicType);
   REGISTER_MATCHER(autoType);
+  REGISTER_MATCHER(decltypeType);
   REGISTER_MATCHER(binaryOperator);
   REGISTER_MATCHER(binaryConditionalOperator);
   REGISTER_MATCHER(blockDecl);
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===================================================================
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -798,6 +798,7 @@
 const AstTypeMatcher<VariableArrayType> variableArrayType;
 const AstTypeMatcher<AtomicType> atomicType;
 const AstTypeMatcher<AutoType> autoType;
+const AstTypeMatcher<DecltypeType> decltypeType;
 const AstTypeMatcher<FunctionType> functionType;
 const AstTypeMatcher<FunctionProtoType> functionProtoType;
 const AstTypeMatcher<ParenType> parenType;
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5063,6 +5063,18 @@
 ///   matches "auto n" and "auto i"
 extern const AstTypeMatcher<AutoType> autoType;
 
+/// Matches types nodes representing C++11 decltype(<expr>) types.
+///
+/// Given:
+/// \code
+///   short i = 1;
+///   int j = 42;
+///   decltype(i + j) result = i + j;
+/// \endcode
+/// decltypeType() 
+///   matches "decltype(i + j)"
+extern const AstTypeMatcher<DecltypeType> decltypeType;
+
 /// Matches \c AutoType nodes where the deduced type is a specific type.
 ///
 /// Note: There is no \c TypeLoc for the deduced type and thus no
@@ -5080,6 +5092,10 @@
 AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
                           AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
 
+/// Matches \c DecltypeType nodes to find out the underlying type.
+AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
+                          AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType));
+
 /// Matches \c FunctionType nodes.
 ///
 /// Given


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48759.153458.patch
Type: text/x-patch
Size: 2216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180629/f782665b/attachment.bin>


More information about the cfe-commits mailing list