From 2d77634e839880704d51656bebd1d2daff661d4e Mon Sep 17 00:00:00 2001 From: Enea Zaffanella Date: Sat, 6 Jul 2013 18:54:58 +0000 Subject: [PATCH] Fixed source location info for UnaryTransformTypeLoc nodes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185765 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchers.h | 10 ++++++++++ lib/Parse/ParseDeclCXX.cpp | 1 + unittests/AST/SourceLocationTest.cpp | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index d6c19b7dfa..110638a278 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -3186,6 +3186,16 @@ AST_TYPE_MATCHER(TypedefType, typedefType); /// instantiation in \c A and the type of the variable declaration in \c B. AST_TYPE_MATCHER(TemplateSpecializationType, templateSpecializationType); +/// \brief Matches types nodes representing unary type transformations. +/// +/// Given: +/// \code +/// typedef __underlying_type(T) type; +/// \endcode +/// unaryTransformType() +/// matches "__underlying_type(T)" +AST_TYPE_MATCHER(UnaryTransformType, unaryTransformType); + /// \brief Matches record types (e.g. structs, classes). /// /// Given diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 67f9c3c7a7..070c9a0120 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -827,6 +827,7 @@ void Parser::ParseUnderlyingTypeSpecifier(DeclSpec &DS) { if (DS.SetTypeSpecType(DeclSpec::TST_underlyingType, StartLoc, PrevSpec, DiagID, Result.release())) Diag(StartLoc, DiagID) << PrevSpec; + DS.setTypeofParensRange(T.getRange()); } /// ParseBaseTypeSpecifier - Parse a C++ base-type-specifier which is either a diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp index 669fcd48a4..be63085b8a 100644 --- a/unittests/AST/SourceLocationTest.cpp +++ b/unittests/AST/SourceLocationTest.cpp @@ -180,5 +180,26 @@ TEST(CXXNewExpr, TypeParenRange) { EXPECT_TRUE(Verifier.match("int* a = new (int);", newExpr())); } +class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier { +protected: + virtual SourceRange getRange(const TypeLoc &Node) { + UnaryTransformTypeLoc T = + Node.getUnqualifiedLoc().castAs(); + assert(!T.isNull()); + return SourceRange(T.getLParenLoc(), T.getRParenLoc()); + } +}; + +TEST(UnaryTransformTypeLoc, ParensRange) { + UnaryTransformTypeLocParensRangeVerifier Verifier; + Verifier.expectRange(3, 26, 3, 28); + EXPECT_TRUE(Verifier.match( + "template \n" + "struct S {\n" + "typedef __underlying_type(T) type;\n" + "};", + loc(unaryTransformType()))); +} + } // end namespace ast_matchers } // end namespace clang -- 2.40.0