r185773 - Fixed source range for functional cast and unresolved construct expr nodes.

Enea Zaffanella zaffanella at cs.unipr.it
Sat Jul 6 23:41:54 PDT 2013


Author: enea
Date: Sun Jul  7 01:41:54 2013
New Revision: 185773

URL: http://llvm.org/viewvc/llvm-project?rev=185773&view=rev
Log:
Fixed source range for functional cast and unresolved construct expr nodes.
Added testcases.

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
    cfe/trunk/unittests/AST/MatchVerifier.h
    cfe/trunk/unittests/AST/SourceLocationTest.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=185773&r1=185772&r2=185773&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sun Jul  7 01:41:54 2013
@@ -1224,7 +1224,9 @@ public:
   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
   SourceLocation getLocStart() const LLVM_READONLY { return TyBeginLoc; }
-  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
+  SourceLocation getLocEnd() const LLVM_READONLY {
+    return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getLocEnd();
+  }
 
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CXXFunctionalCastExprClass;
@@ -3069,7 +3071,10 @@ public:
   }
 
   SourceLocation getLocStart() const LLVM_READONLY;
-  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
+  SourceLocation getLocEnd() const LLVM_READONLY {
+    assert(RParenLoc.isValid() || NumArgs == 1);
+    return RParenLoc.isValid() ? RParenLoc : getArg(0)->getLocEnd();
+  }
 
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CXXUnresolvedConstructExprClass;

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=185773&r1=185772&r2=185773&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Sun Jul  7 01:41:54 2013
@@ -640,6 +640,18 @@ const internal::VariadicDynCastAllOfMatc
   Stmt,
   CXXConstructExpr> constructExpr;
 
+/// \brief Matches unresolved constructor call expressions.
+///
+/// Example matches T(t) in return statement of f
+///     (matcher = unresolvedConstructExpr())
+/// \code
+///   template <typename T>
+///   void f(const T& t) { return T(t); }
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Stmt,
+  CXXUnresolvedConstructExpr> unresolvedConstructExpr;
+
 /// \brief Matches implicit and explicit this expressions.
 ///
 /// Example matches the implicit this expression in "return i".

Modified: cfe/trunk/unittests/AST/MatchVerifier.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/MatchVerifier.h?rev=185773&r1=185772&r2=185773&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/MatchVerifier.h (original)
+++ cfe/trunk/unittests/AST/MatchVerifier.h Sun Jul  7 01:41:54 2013
@@ -25,7 +25,7 @@
 namespace clang {
 namespace ast_matchers {
 
-enum Language { Lang_C, Lang_C89, Lang_CXX, Lang_OpenCL };
+enum Language { Lang_C, Lang_C89, Lang_CXX, Lang_CXX11, Lang_OpenCL };
 
 /// \brief Base class for verifying some property of nodes found by a matcher.
 template <typename NodeType>
@@ -85,6 +85,10 @@ testing::AssertionResult MatchVerifier<N
     Args.push_back("-std=c++98");
     FileName = "input.cc";
     break;
+  case Lang_CXX11:
+    Args.push_back("-std=c++11");
+    FileName = "input.cc";
+    break;
   case Lang_OpenCL:
     FileName = "input.cl";
   }

Modified: cfe/trunk/unittests/AST/SourceLocationTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/SourceLocationTest.cpp?rev=185773&r1=185772&r2=185773&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/SourceLocationTest.cpp (original)
+++ cfe/trunk/unittests/AST/SourceLocationTest.cpp Sun Jul  7 01:41:54 2013
@@ -201,5 +201,26 @@ TEST(UnaryTransformTypeLoc, ParensRange)
       loc(unaryTransformType())));
 }
 
+TEST(CXXFunctionalCastExpr, SourceRange) {
+  RangeVerifier<CXXFunctionalCastExpr> Verifier;
+  Verifier.expectRange(2, 10, 2, 14);
+  EXPECT_TRUE(Verifier.match(
+      "int foo() {\n"
+      "  return int{};\n"
+      "}",
+      functionalCastExpr(), Lang_CXX11));
+}
+
+TEST(CXXUnresolvedConstructExpr, SourceRange) {
+  RangeVerifier<CXXUnresolvedConstructExpr> Verifier;
+  Verifier.expectRange(3, 10, 3, 12);
+  EXPECT_TRUE(Verifier.match(
+      "template <typename U>\n"
+      "U foo() {\n"
+      "  return U{};\n"
+      "}",
+      unresolvedConstructExpr(), Lang_CXX11));
+}
+
 } // end namespace ast_matchers
 } // end namespace clang





More information about the cfe-commits mailing list