| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #include "TestVisitor.h" |
| 10 | |
| 11 | using namespace clang; |
| 12 | |
| 13 | namespace { |
| 14 | |
| 15 | |
| 16 | |
| 17 | class AttrVisitor : public ExpectedLocationVisitor<AttrVisitor> { |
| 18 | public: |
| 19 | bool VisitMemberExpr(MemberExpr *ME) { |
| 20 | Match(ME->getMemberDecl()->getNameAsString(), ME->getBeginLoc()); |
| 21 | return true; |
| 22 | } |
| 23 | bool VisitAttr(Attr *A) { |
| 24 | Match("Attr", A->getLocation()); |
| 25 | return true; |
| 26 | } |
| 27 | bool VisitGuardedByAttr(GuardedByAttr *A) { |
| 28 | Match("guarded_by", A->getLocation()); |
| 29 | return true; |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | TEST(RecursiveASTVisitor, AttributesAreVisited) { |
| 35 | AttrVisitor Visitor; |
| 36 | Visitor.ExpectMatch("Attr", 4, 24); |
| 37 | Visitor.ExpectMatch("guarded_by", 4, 24); |
| 38 | Visitor.ExpectMatch("mu1", 4, 35); |
| 39 | Visitor.ExpectMatch("Attr", 5, 29); |
| 40 | Visitor.ExpectMatch("mu1", 5, 54); |
| 41 | Visitor.ExpectMatch("mu2", 5, 59); |
| 42 | EXPECT_TRUE(Visitor.runOver( |
| 43 | "class Foo {\n" |
| 44 | " int mu1;\n" |
| 45 | " int mu2;\n" |
| 46 | " int a __attribute__((guarded_by(mu1)));\n" |
| 47 | " void bar() __attribute__((exclusive_locks_required(mu1, mu2)));\n" |
| 48 | "};\n")); |
| 49 | } |
| 50 | |
| 51 | } |
| 52 | |