diff options
author | dim <dim@FreeBSD.org> | 2014-11-24 09:15:30 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2014-11-24 09:15:30 +0000 |
commit | 173a4f43a911175643bda81ee675e8d9269056ea (patch) | |
tree | 47df2c12b57214af6c31e47404b005675b8b7ffc /unittests/Tooling/RecursiveASTVisitorTest.cpp | |
parent | 88f7a7d5251a2d813460274c92decc143a11569b (diff) | |
download | FreeBSD-src-173a4f43a911175643bda81ee675e8d9269056ea.zip FreeBSD-src-173a4f43a911175643bda81ee675e8d9269056ea.tar.gz |
Vendor import of clang RELEASE_350/final tag r216957 (effectively, 3.5.0 release):
https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_350/final@216957
Diffstat (limited to 'unittests/Tooling/RecursiveASTVisitorTest.cpp')
-rw-r--r-- | unittests/Tooling/RecursiveASTVisitorTest.cpp | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/unittests/Tooling/RecursiveASTVisitorTest.cpp b/unittests/Tooling/RecursiveASTVisitorTest.cpp index 3234767..a1a93a5 100644 --- a/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/unittests/Tooling/RecursiveASTVisitorTest.cpp @@ -8,10 +8,11 @@ //===----------------------------------------------------------------------===// #include "TestVisitor.h" - #include <stack> -namespace clang { +using namespace clang; + +namespace { class TypeLocVisitor : public ExpectedLocationVisitor<TypeLocVisitor> { public: @@ -530,6 +531,15 @@ TEST(RecursiveASTVisitor, VisitsCompoundLiteralType) { TypeLocVisitor::Lang_C)); } +TEST(RecursiveASTVisitor, VisitsObjCPropertyType) { + TypeLocVisitor Visitor; + Visitor.ExpectMatch("NSNumber", 2, 33); + EXPECT_TRUE(Visitor.runOver( + "@class NSNumber; \n" + "@interface A @property (retain) NSNumber *x; @end\n", + TypeLocVisitor::Lang_OBJC)); +} + TEST(RecursiveASTVisitor, VisitsLambdaExpr) { LambdaExprVisitor Visitor; Visitor.ExpectMatch("", 1, 12); @@ -551,6 +561,16 @@ TEST(RecursiveASTVisitor, HasCaptureDefaultLoc) { LambdaDefaultCaptureVisitor::Lang_CXX11)); } +TEST(RecursiveASTVisitor, VisitsCopyExprOfBlockDeclCapture) { + DeclRefExprVisitor Visitor; + Visitor.ExpectMatch("x", 3, 24); + EXPECT_TRUE(Visitor.runOver("void f(int(^)(int)); \n" + "void g() { \n" + " f([&](int x){ return x; }); \n" + "}", + DeclRefExprVisitor::Lang_OBJCXX11)); +} + // Checks for lambda classes that are not marked as implicitly-generated. // (There should be none.) class ClassVisitor : public ExpectedLocationVisitor<ClassVisitor> { @@ -577,4 +597,42 @@ TEST(RecursiveASTVisitor, LambdaClosureTypesAreImplicit) { EXPECT_TRUE(Visitor.sawOnlyImplicitLambdaClasses()); } -} // end namespace clang + + +// Check to ensure that attributes and expressions within them are being +// visited. +class AttrVisitor : public ExpectedLocationVisitor<AttrVisitor> { +public: + bool VisitMemberExpr(MemberExpr *ME) { + Match(ME->getMemberDecl()->getNameAsString(), ME->getLocStart()); + return true; + } + bool VisitAttr(Attr *A) { + Match("Attr", A->getLocation()); + return true; + } + bool VisitGuardedByAttr(GuardedByAttr *A) { + Match("guarded_by", A->getLocation()); + return true; + } +}; + + +TEST(RecursiveASTVisitor, AttributesAreVisited) { + AttrVisitor Visitor; + Visitor.ExpectMatch("Attr", 4, 24); + Visitor.ExpectMatch("guarded_by", 4, 24); + Visitor.ExpectMatch("mu1", 4, 35); + Visitor.ExpectMatch("Attr", 5, 29); + Visitor.ExpectMatch("mu1", 5, 54); + Visitor.ExpectMatch("mu2", 5, 59); + EXPECT_TRUE(Visitor.runOver( + "class Foo {\n" + " int mu1;\n" + " int mu2;\n" + " int a __attribute__((guarded_by(mu1)));\n" + " void bar() __attribute__((exclusive_locks_required(mu1, mu2)));\n" + "};\n")); +} + +} // end anonymous namespace |