forked from OSchip/llvm-project
Add an AST matcher for hasDefaultArgument() to match on parameter declarations that have a default value.
Patch by Julie Hockett. llvm-svn: 318794
This commit is contained in:
parent
b67ce00e4d
commit
5f8980a995
|
@ -3183,6 +3183,15 @@ Usable as: Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1TagDe
|
|||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1ParmVarDecl.html">ParmVarDecl</a>></td><td class="name" onclick="toggle('hasDefaultArgument0')"><a name="hasDefaultArgument0Anchor">hasDefaultArgument</a></td><td></td></tr>
|
||||
<tr><td colspan="4" class="doc" id="hasDefaultArgument0"><pre>Matches a declaration that has default arguments.
|
||||
|
||||
Example matches y (matcher = parmVarDecl(hasDefaultArgument()))
|
||||
void x(int val) {}
|
||||
void y(int val = 0) {}
|
||||
</pre></td></tr>
|
||||
|
||||
|
||||
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">QualType</a>></td><td class="name" onclick="toggle('asString0')"><a name="asString0Anchor">asString</a></td><td>std::string Name</td></tr>
|
||||
<tr><td colspan="4" class="doc" id="asString0"><pre>Matches if the matched type is represented by the given string.
|
||||
|
||||
|
|
|
@ -5817,6 +5817,17 @@ AST_MATCHER(NamedDecl, hasExternalFormalLinkage) {
|
|||
return Node.hasExternalFormalLinkage();
|
||||
}
|
||||
|
||||
/// \brief Matches a declaration that has default arguments.
|
||||
///
|
||||
/// Example matches y (matcher = parmVarDecl(hasDefaultArgument()))
|
||||
/// \code
|
||||
/// void x(int val) {}
|
||||
/// void y(int val = 0) {}
|
||||
/// \endcode
|
||||
AST_MATCHER(ParmVarDecl, hasDefaultArgument) {
|
||||
return Node.hasDefaultArg();
|
||||
}
|
||||
|
||||
} // namespace ast_matchers
|
||||
} // namespace clang
|
||||
|
||||
|
|
|
@ -248,6 +248,7 @@ RegistryMaps::RegistryMaps() {
|
|||
REGISTER_MATCHER(hasDeclaration);
|
||||
REGISTER_MATCHER(hasDeclContext);
|
||||
REGISTER_MATCHER(hasDeducedType);
|
||||
REGISTER_MATCHER(hasDefaultArgument);
|
||||
REGISTER_MATCHER(hasDescendant);
|
||||
REGISTER_MATCHER(hasDestinationType);
|
||||
REGISTER_MATCHER(hasDynamicExceptionSpec);
|
||||
|
|
|
@ -1991,5 +1991,12 @@ TEST(HasExternalFormalLinkage, Basic) {
|
|||
namedDecl(hasExternalFormalLinkage())));
|
||||
}
|
||||
|
||||
TEST(HasDefaultArgument, Basic) {
|
||||
EXPECT_TRUE(matches("void x(int val = 0) {}",
|
||||
parmVarDecl(hasDefaultArgument())));
|
||||
EXPECT_TRUE(notMatches("void x(int val) {}",
|
||||
parmVarDecl(hasDefaultArgument())));
|
||||
}
|
||||
|
||||
} // namespace ast_matchers
|
||||
} // namespace clang
|
||||
|
|
Loading…
Reference in New Issue