r264417 - [ASTMatchers] Add own version of VariadicFunction.

Samuel Benzaquen via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 25 12:25:57 PDT 2016


I believe r264428 fixes this problem.

On Fri, Mar 25, 2016 at 2:18 PM, Mehdi Amini <mehdi.amini at apple.com> wrote:

> Hi,
>
> I think this broke clang-tidy somehow:
> http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10881/steps/build%20stage%201/logs/stdio
>
> --
> Mehdi
>
>
>
>
> > On Mar 25, 2016, at 9:29 AM, Samuel Benzaquen via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
> >
> > Author: sbenza
> > Date: Fri Mar 25 11:29:30 2016
> > New Revision: 264417
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev
> > Log:
> > [ASTMatchers] Add own version of VariadicFunction.
> >
> > Summary:
> > llvm::VariadicFunction is only being used by ASTMatchers.
> > Having our own copy here allows us to remove the other one from llvm/ADT.
> > Also, we can extend the API to meet our needs without modifying the
> common
> > implementation.
> >
> > Reviewers: alexfh
> >
> > Subscribers: klimek, cfe-commits
> >
> > Differential Revision: http://reviews.llvm.org/D18275
> >
> > Modified:
> >    cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> >    cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> >    cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
> >    cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> >
> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25
> 11:29:30 2016
> > @@ -1990,8 +1990,8 @@ inline internal::Matcher<NamedDecl> hasN
> > /// \code
> > ///     anyOf(hasName(a), hasName(b), hasName(c))
> > /// \endcode
> > -const llvm::VariadicFunction<internal::Matcher<NamedDecl>, StringRef,
> > -                             internal::hasAnyNameFunc>
> > +const internal::VariadicFunction<internal::Matcher<NamedDecl>,
> StringRef,
> > +                                 internal::hasAnyNameFunc>
> >     hasAnyName = {};
> >
> > /// \brief Matches NamedDecl nodes whose fully qualified names contain
> >
> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25
> 11:29:30 2016
> > @@ -46,8 +46,9 @@
> > #include "clang/AST/StmtCXX.h"
> > #include "clang/AST/StmtObjC.h"
> > #include "clang/AST/Type.h"
> > +#include "llvm/ADT/ArrayRef.h"
> > #include "llvm/ADT/Optional.h"
> > -#include "llvm/ADT/VariadicFunction.h"
> > +#include "llvm/ADT/SmallVector.h"
> > #include "llvm/Support/ManagedStatic.h"
> > #include <map>
> > #include <string>
> > @@ -60,6 +61,39 @@ class BoundNodes;
> >
> > namespace internal {
> >
> > +/// \brief Variadic function object.
> > +///
> > +/// Most of the functions below that use VariadicFunction could be
> implemented
> > +/// using plain C++11 variadic functions, but the function object
> allows us to
> > +/// capture it on the dynamic matcher registry.
> > +template <typename ResultT, typename ArgT,
> > +          ResultT (*Func)(ArrayRef<const ArgT *>)>
> > +struct VariadicFunction {
> > +  ResultT operator()() const { return Func({}); }
> > +
> > +  template <typename... ArgsT>
> > +  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
> > +    return Execute(Arg1, static_cast<const ArgT &>(Args)...);
> > +  }
> > +
> > +  // We also allow calls with an already created array, in case the
> caller
> > +  // already had it.
> > +  ResultT operator()(ArrayRef<ArgT> Args) const {
> > +    SmallVector<const ArgT*, 8> InnerArgs;
> > +    for (const ArgT &Arg : Args)
> > +      InnerArgs.push_back(&Arg);
> > +    return Func(InnerArgs);
> > +  }
> > +
> > +private:
> > +  // Trampoline function to allow for implicit conversions to take place
> > +  // before we make the array.
> > +  template <typename... ArgsT> ResultT Execute(const ArgsT &... Args)
> const {
> > +    const ArgT *const ArgsArray[] = {&Args...};
> > +    return Func(ArgsArray);
> > +  }
> > +};
> > +
> > /// \brief Unifies obtaining the underlying type of a regular node
> through
> > /// `getType` and a TypedefNameDecl node through `getUnderlyingType`.
> > template <typename NodeType>
> > @@ -1405,9 +1439,8 @@ inline bool ValueEqualsMatcher<FloatingL
> > /// casted to CXXRecordDecl and all given matchers match.
> > template <typename SourceT, typename TargetT>
> > class VariadicDynCastAllOfMatcher
> > -    : public llvm::VariadicFunction<
> > -        BindableMatcher<SourceT>, Matcher<TargetT>,
> > -        makeDynCastAllOfComposite<SourceT, TargetT> > {
> > +    : public VariadicFunction<BindableMatcher<SourceT>,
> Matcher<TargetT>,
> > +                              makeDynCastAllOfComposite<SourceT,
> TargetT>> {
> > public:
> >   VariadicDynCastAllOfMatcher() {}
> > };
> > @@ -1423,9 +1456,9 @@ public:
> > /// \c Matcher<NestedNameSpecifier>.
> > /// The returned matcher matches if all given matchers match.
> > template <typename T>
> > -class VariadicAllOfMatcher : public llvm::VariadicFunction<
> > -                               BindableMatcher<T>, Matcher<T>,
> > -                               makeAllOfComposite<T> > {
> > +class VariadicAllOfMatcher
> > +    : public VariadicFunction<BindableMatcher<T>, Matcher<T>,
> > +                              makeAllOfComposite<T>> {
> > public:
> >   VariadicAllOfMatcher() {}
> > };
> > @@ -1546,8 +1579,8 @@ public:
> >         new MatcherImpl<OuterT>(InnerMatcher, Getter<OuterT>::value()));
> >   }
> >
> > -  struct Func : public llvm::VariadicFunction<Self, Matcher<InnerTBase>,
> > -                                              &Self::create> {
> > +  struct Func
> > +      : public VariadicFunction<Self, Matcher<InnerTBase>,
> &Self::create> {
> >     Func() {}
> >   };
> >
> >
> > Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h?rev=264417&r1=264416&r2=264417&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h (original)
> > +++ cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h Fri Mar 25 11:29:30
> 2016
> > @@ -325,8 +325,9 @@ public:
> >
> >   template <typename ResultT, typename ArgT,
> >             ResultT (*F)(ArrayRef<const ArgT *>)>
> > -  VariadicFuncMatcherDescriptor(llvm::VariadicFunction<ResultT, ArgT,
> F> Func,
> > -                          StringRef MatcherName)
> > +  VariadicFuncMatcherDescriptor(
> > +      ast_matchers::internal::VariadicFunction<ResultT, ArgT, F> Func,
> > +      StringRef MatcherName)
> >       : Func(&variadicMatcherDescriptor<ResultT, ArgT, F>),
> >         MatcherName(MatcherName.str()),
> >         ArgsKind(ArgTypeTraits<ArgT>::getKind()) {
> > @@ -655,9 +656,9 @@ MatcherDescriptor *makeMatcherAutoMarsha
> > /// \brief Variadic overload.
> > template <typename ResultT, typename ArgT,
> >           ResultT (*Func)(ArrayRef<const ArgT *>)>
> > -MatcherDescriptor *
> > -makeMatcherAutoMarshall(llvm::VariadicFunction<ResultT, ArgT, Func>
> VarFunc,
> > -                        StringRef MatcherName) {
> > +MatcherDescriptor *makeMatcherAutoMarshall(
> > +    ast_matchers::internal::VariadicFunction<ResultT, ArgT, Func>
> VarFunc,
> > +    StringRef MatcherName) {
> >   return new VariadicFuncMatcherDescriptor(VarFunc, MatcherName);
> > }
> >
> >
> > Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=264417&r1=264416&r2=264417&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
> > +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Fri Mar 25
> 11:29:30 2016
> > @@ -3000,6 +3000,9 @@ TEST(Matcher, HasAnyName) {
> >   EXPECT_TRUE(notMatches(Code, recordDecl(hasAnyName("::C", "::b::C"))));
> >   EXPECT_TRUE(
> >       matches(Code, recordDecl(hasAnyName("::C", "::b::C",
> "::a::b::C"))));
> > +
> > +  std::vector<StringRef> Names = {"::C", "::b::C", "::a::b::C"};
> > +  EXPECT_TRUE(matches(Code, recordDecl(hasAnyName(Names))));
> > }
> >
> > TEST(Matcher, IsDefinition) {
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160325/dfa98806/attachment-0001.html>


More information about the cfe-commits mailing list