1//===- unittest/Tooling/RecursiveASTVisitorTests/Attr.cpp -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "CRTPTestVisitor.h"
10
11using namespace clang;
12
13namespace {
14
15// Check to ensure that attributes and expressions within them are being
16// visited.
17class AttrVisitor : public CRTPExpectedLocationVisitor<AttrVisitor> {
18public:
19 bool VisitMemberExpr(MemberExpr *ME) {
20 Match(Name: ME->getMemberDecl()->getNameAsString(), Location: ME->getBeginLoc());
21 return true;
22 }
23 bool VisitAttr(Attr *A) {
24 Match(Name: "Attr", Location: A->getLocation());
25 return true;
26 }
27 bool VisitGuardedByAttr(GuardedByAttr *A) {
28 Match(Name: "guarded_by", Location: A->getLocation());
29 return true;
30 }
31};
32
33TEST(RecursiveASTVisitor, AttributesAreVisited) {
34 AttrVisitor Visitor;
35 Visitor.ExpectMatch(Match: "Attr", Line: 4, Column: 24);
36 Visitor.ExpectMatch(Match: "guarded_by", Line: 4, Column: 24);
37 Visitor.ExpectMatch(Match: "mu1", Line: 4, Column: 35);
38 Visitor.ExpectMatch(Match: "Attr", Line: 5, Column: 29);
39 Visitor.ExpectMatch(Match: "mu1", Line: 5, Column: 54);
40 Visitor.ExpectMatch(Match: "mu2", Line: 5, Column: 59);
41 EXPECT_TRUE(Visitor.runOver(
42 "class Foo {\n"
43 " int mu1;\n"
44 " int mu2;\n"
45 " int a __attribute__((guarded_by(mu1)));\n"
46 " void bar() __attribute__((exclusive_locks_required(mu1, mu2)));\n"
47 "};\n"));
48}
49
50} // end anonymous namespace
51

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of clang/unittests/Tooling/RecursiveASTVisitorTests/Attr.cpp