This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Added hasAnyListedName matcher
Needs ReviewPublic

Authored by njames93 on Mar 10 2020, 5:23 AM.

Details

Summary

Adds a utils matcher called hasAnyListedName to alleviate all the hackery using the hasAnyName matcher with types that are already vector<string>

Diff Detail

Event Timeline

njames93 created this revision.Mar 10 2020, 5:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2020, 5:23 AM
njames93 updated this revision to Diff 249356.Mar 10 2020, 6:33 AM
  • Fix formatting
gribozavr2 added inline comments.Mar 10 2020, 6:36 AM
clang-tools-extra/clang-tidy/utils/Matchers.cpp
18

This matcher sounds generally useful. I think it would be better placed in ASTMatchers.h, WDYT? Can we make it an overload of hasAnyName?

njames93 added inline comments.Mar 10 2020, 7:07 AM
clang-tools-extra/clang-tidy/utils/Matchers.cpp
18

hasAnyName is a const variable who's type is VariadicFunction so it can't be overloaded unfortunately. I personally didn't want it in ASTMatchers.h as its mainly useful for clang-tidy checks that load in configurations. It doesn't have a place in say clang-query.

Eugene.Zelenko edited reviewers, added: njames93; removed: Eugene.Zelenko.Mar 10 2020, 7:55 AM
Eugene.Zelenko added a project: Restricted Project.
gribozavr2 added inline comments.Mar 10 2020, 8:15 AM
clang-tools-extra/clang-tidy/utils/Matchers.cpp
18

hasAnyName is a const variable who's type is VariadicFunction so it can't be overloaded unfortunately.

I thought we had facilities to declare polymorphic matchers that could help here.

I personally didn't want it in ASTMatchers.h as its mainly useful for clang-tidy checks that load in configurations.

A lot of user-defined tools are quite similar.

njames93 marked an inline comment as done.Mar 10 2020, 4:57 PM
njames93 added inline comments.
clang-tools-extra/clang-tidy/utils/Matchers.cpp
18

Polymorphic matchers are matchers that can match against different types of nodes, what we want here is match against one type of node, but different overloads. I am thinking though that With some nifty retooling of VariadicFunction you could possible change it so that you can call its operator() with types that are convertible to its ArgT. However that is a deep rabbit hole to go down for the purpose of what this patch is trying to do

alexfh added inline comments.Mar 12 2020, 4:46 PM
clang-tools-extra/clang-tidy/utils/Matchers.h
53–55

We could change all checks to use the other overload and drop this one (and the utils::options::parseStringList() call in each check's constructor). WDYT?

njames93 marked an inline comment as done.Mar 13 2020, 3:09 AM
njames93 added inline comments.
clang-tools-extra/clang-tidy/utils/Matchers.h
53–55

I'm not sold on that, I'd like the conventions of all checks to be the same wrt option lists, however those option lists aren't only used for names of decls.