diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2015-11-18 17:05:39 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2015-11-18 17:05:39 +0000 |
commit | 34e0bd40e4c30f9df5e32fb91071467194b2deb0 (patch) | |
tree | 3b39af97f6ce3e3a300fd692bc06403e40170a80 /clang/unittests/ASTMatchers/ASTMatchersTest.cpp | |
parent | 94ef41ff1d93e6380f63f5715430624094842b31 (diff) | |
download | bcm5719-llvm-34e0bd40e4c30f9df5e32fb91071467194b2deb0.tar.gz bcm5719-llvm-34e0bd40e4c30f9df5e32fb91071467194b2deb0.zip |
Adding AST matchers for VarDecl storage durations. Can now determine whether a VarDecl has automatic, static, or thread storage duration. This also updates the documentation for matchers, which appear to be missing some previous additions.
llvm-svn: 253473
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 476a0be2904..6d81bd88b9e 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1355,6 +1355,29 @@ TEST(Matcher, VarDecl_Storage) { EXPECT_TRUE(matches("void f() { static int X; }", M)); } +TEST(Matcher, VarDecl_StorageDuration) { + std::string T = + "void f() { int x; static int y; thread_local int z; } int a;"; + + EXPECT_TRUE(matches(T, varDecl(hasName("x"), hasAutomaticStorageDuration()))); + EXPECT_TRUE( + notMatches(T, varDecl(hasName("y"), hasAutomaticStorageDuration()))); + EXPECT_TRUE( + notMatches(T, varDecl(hasName("z"), hasAutomaticStorageDuration()))); + EXPECT_TRUE( + notMatches(T, varDecl(hasName("a"), hasAutomaticStorageDuration()))); + + EXPECT_TRUE(matches(T, varDecl(hasName("y"), hasStaticStorageDuration()))); + EXPECT_TRUE(matches(T, varDecl(hasName("a"), hasStaticStorageDuration()))); + EXPECT_TRUE(notMatches(T, varDecl(hasName("x"), hasStaticStorageDuration()))); + EXPECT_TRUE(notMatches(T, varDecl(hasName("z"), hasStaticStorageDuration()))); + + EXPECT_TRUE(matches(T, varDecl(hasName("z"), hasThreadStorageDuration()))); + EXPECT_TRUE(notMatches(T, varDecl(hasName("x"), hasThreadStorageDuration()))); + EXPECT_TRUE(notMatches(T, varDecl(hasName("y"), hasThreadStorageDuration()))); + EXPECT_TRUE(notMatches(T, varDecl(hasName("a"), hasThreadStorageDuration()))); +} + TEST(Matcher, FindsVarDeclInFunctionParameter) { EXPECT_TRUE(matches( "void f(int i) {}", |