diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2015-10-05 14:41:27 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2015-10-05 14:41:27 +0000 |
commit | 3fd6c110bea17628828e1d149906312343cac99e (patch) | |
tree | d38337773bbf7097f6f37aea836cdf934d94fbe8 | |
parent | 2b4e14ed588d974985911bf6ad64178f022257b4 (diff) | |
download | bcm5719-llvm-3fd6c110bea17628828e1d149906312343cac99e.tar.gz bcm5719-llvm-3fd6c110bea17628828e1d149906312343cac99e.zip |
Adding a narrowing AST matcher for FunctionDecl::isVariadic(), plus tests and documentation.
llvm-svn: 249321
-rw-r--r-- | clang/docs/LibASTMatchersReference.html | 12 | ||||
-rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 14 | ||||
-rw-r--r-- | clang/lib/ASTMatchers/Dynamic/Registry.cpp | 1 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 7 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.h | 7 |
5 files changed, 41 insertions, 0 deletions
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index 47666a13867..cab709e3a64 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -2210,6 +2210,18 @@ Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Functi </pre></td></tr>
+<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isVariadic0')"><a name="isVariadic0Anchor">isVariadic</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isVariadic0"><pre>Matches if a function declaration is variadic.
+
+Example matches f, but not g or h. The function i will not match, event when
+compiled in C mode.
+ void f(...);
+ void g(int);
+ template <typename... Ts> void h(Ts...);
+ void i();
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('parameterCountIs0')"><a name="parameterCountIs0Anchor">parameterCountIs</a></td><td>unsigned N</td></tr>
<tr><td colspan="4" class="doc" id="parameterCountIs0"><pre>Matches FunctionDecls that have a specific parameter count.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 5a14eef72a8..cfed1fd16de 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -3255,6 +3255,20 @@ AST_POLYMORPHIC_MATCHER(isDefinition, return Node.isThisDeclarationADefinition(); } +/// \brief Matches if a function declaration is variadic. +/// +/// Example matches f, but not g or h. The function i will not match, even when +/// compiled in C mode. +/// \code +/// void f(...); +/// void g(int); +/// template <typename... Ts> void h(Ts...); +/// void i(); +/// \endcode +AST_MATCHER(FunctionDecl, isVariadic) { + return Node.isVariadic(); +} + /// \brief Matches the class declaration that the given method declaration /// belongs to. /// diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index 1bf4c5b21d1..81e3ffd8f91 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -291,6 +291,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(isStruct); REGISTER_MATCHER(isTemplateInstantiation); REGISTER_MATCHER(isUnion); + REGISTER_MATCHER(isVariadic); REGISTER_MATCHER(isVirtual); REGISTER_MATCHER(isWritten); REGISTER_MATCHER(labelStmt); diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 7f553513daa..a15d6ac2be5 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1511,6 +1511,13 @@ TEST(Function, MatchesFunctionDeclarations) { notMatches("void f(int);" "template <typename T> struct S { void g(T t) { f(t); } };", CallFunctionF)); + + EXPECT_TRUE(matches("void f(...);", functionDecl(isVariadic()))); + EXPECT_TRUE(notMatches("void f(int);", functionDecl(isVariadic()))); + EXPECT_TRUE(notMatches("template <typename... Ts> void f(Ts...);", + functionDecl(isVariadic()))); + EXPECT_TRUE(notMatches("void f();", functionDecl(isVariadic()))); + EXPECT_TRUE(notMatchesC("void f();", functionDecl(isVariadic()))); } TEST(FunctionTemplate, MatchesFunctionTemplateDeclarations) { diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h b/clang/unittests/ASTMatchers/ASTMatchersTest.h index 285d2630cea..9ed7ef66e51 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.h +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h @@ -126,6 +126,13 @@ testing::AssertionResult matchesC(const std::string &Code, const T &AMatcher) { } template <typename T> +testing::AssertionResult notMatchesC(const std::string &Code, + const T &AMatcher) { + return matchesConditionally(Code, AMatcher, false, "", FileContentMappings(), + "input.c"); +} + +template <typename T> testing::AssertionResult notMatchesObjC(const std::string &Code, const T &AMatcher) { return matchesConditionally( |