r249321 - Adding a narrowing AST matcher for FunctionDecl::isVariadic(), plus tests and documentation.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 5 07:51:23 PDT 2015
On Mon, Oct 5, 2015 at 10:49 AM, mats petersson <mats at planetcatfish.com> wrote:
>
>
> On 5 October 2015 at 15:41, Aaron Ballman via cfe-commits
> <cfe-commits at lists.llvm.org> wrote:
>>
>> Author: aaronballman
>> Date: Mon Oct 5 09:41:27 2015
>> New Revision: 249321
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=249321&view=rev
>> Log:
>> Adding a narrowing AST matcher for FunctionDecl::isVariadic(), plus tests
>> and documentation.
>>
>> Modified:
>> cfe/trunk/docs/LibASTMatchersReference.html
>> cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>> cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
>> cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
>> cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
>>
>> Modified: cfe/trunk/docs/LibASTMatchersReference.html
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=249321&r1=249320&r2=249321&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/docs/LibASTMatchersReference.html (original)
>> +++ cfe/trunk/docs/LibASTMatchersReference.html Mon Oct 5 09:41:27 2015
>> @@ -2210,6 +2210,18 @@ Usable as: Matcher<<a href="http://cla
>> </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.
>>
>>
>> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=249321&r1=249320&r2=249321&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
>> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Oct 5 09:41:27
>> 2015
>> @@ -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.
>> ///
>>
>> Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=249321&r1=249320&r2=249321&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
>> +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Mon Oct 5 09:41:27
>> 2015
>> @@ -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);
>>
>> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=249321&r1=249320&r2=249321&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
>> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Mon Oct 5
>> 09:41:27 2015
>> @@ -1511,6 +1511,13 @@ TEST(Function, MatchesFunctionDeclaratio
>> 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())));
>
> Am I missing something - surely this should be EXPECT_FALSE?
EXPECT_TRUE is correct -- the test is using notMatches() instead of matches().
~Aaron
>
> --
> Mats
>>
>> + 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) {
>>
>> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h?rev=249321&r1=249320&r2=249321&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h (original)
>> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h Mon Oct 5 09:41:27
>> 2015
>> @@ -126,6 +126,13 @@ testing::AssertionResult matchesC(const
>> }
>>
>> 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(
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
More information about the cfe-commits
mailing list