This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatchers] Adds `CXXMemberCallExpr` matcher `invokedAtType`.
AbandonedPublic

Authored by ymandel on Jan 17 2019, 5:49 AM.

Details

Summary

This matcher is a variant of thisPointerType, like on is a variant of onImplicitObjectArgument.

We also add a test for the matcher and update reference HTML accordingly.

Event Timeline

ymandel created this revision.Jan 17 2019, 5:49 AM
ymandel retitled this revision from Adds `CXXMemberCallExpr` matcher `invokedAtType`. to [ASTMatchers] Adds `CXXMemberCallExpr` matcher `invokedAtType`..Jan 17 2019, 5:51 AM

Please always subscribe lists.
The reviews that happen without lists are null and void.

lebedev.ri set the repository for this revision to rC Clang.Jan 17 2019, 5:57 AM
alexfh added inline comments.Jan 25 2019, 5:58 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

The name of the matcher doesn't tell me much. I had to carefully read the documentation to understand what is it about. I don't have a name that would raise no questions and wouldn't be too verbose at the same time, but a bit of verbosity wouldn't hurt I guess. How about objectTypeAsWritten?

3301 ↗(On Diff #182263)

nit: clang:: and clang::ast_matchers:: are unnecessary. Same below

aaron.ballman added inline comments.Jan 25 2019, 7:08 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

Yeah, I think this would be a better name. Also, having some examples that demonstrate where this behavior differs from thisPointerType would be helpful.

ymandel marked 2 inline comments as done.Jan 25 2019, 10:52 AM
ymandel added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

Agreed that it needs a new name, but I'm having trouble finding one I'm satisfied with. Here's the full description: "the type of the written implicit object argument". I base this phrasing on the class CXXMemberCallExpr's terminology. In x.f(5), x is the implicit object argument, whether or not it is also implicitly surrounded by a cast. That is, "implicit" has two different meanings in this context.

So, with that, how about writtenObjectType? It's close to objectTypeAsWritten but I'm hoping it makes more clear that the "written" part is the object not the type.

ymandel updated this revision to Diff 183582.Jan 25 2019, 11:10 AM

Remove unneeded qualifiers and clarify constrast with thisPointerType.

ymandel marked 3 inline comments as done.Jan 25 2019, 11:12 AM
ymandel added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

I've contrasted the behavior with thisPointerType in both of the examples. Do you think this helps or do you want something more explicit?

aaron.ballman added inline comments.Jan 25 2019, 11:22 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

Here's a totally different direction: onOrPointsToType()

cxxMemberCallExpr(onOrPointsToType(hasDeclaration(cxxRecordDecl(hasName("Y")))))
3300 ↗(On Diff #182263)

I think more explicit would be better. e.g.,

cxxMemberCallExpr(invokedAtType(hasDeclaration(cxxRecordDecl(hasName("X")))))
matches 'x.m()' and 'p->m()'.
cxxMemberCallExpr(on(thisPointerType(hasDeclaration(cxxRecordDecl(hasName("X"))))))
matches nothing because the type of 'this' is 'Y' in both cases.
ymandel updated this revision to Diff 183591.Jan 25 2019, 11:49 AM

Contrast to thisPointerType with explicit examples.

ymandel marked 3 inline comments as done.Jan 25 2019, 11:53 AM
ymandel added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

But, what about even simpler: onType? I think this parallels the intuition of the name thisPointerType. onType(T) should match x.f and x->f, where x is type T.

aaron.ballman added inline comments.Jan 25 2019, 12:44 PM
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

You've pointed out why I don't think onType works -- it doesn't match on type T -- it matches on type T, or a pointer/reference to type T, which is pretty different. Someone reading the matcher may expect an exact type match and insert a pointerType() or something there thinking they need to do that to match a call through a pointer.

@alexfh, opinions?

clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
473 ↗(On Diff #183591)

The test name is using the old name for the matcher.

474 ↗(On Diff #183591)

Same here as well.

ymandel marked 2 inline comments as done.Jan 28 2019, 6:39 AM
ymandel added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

True. I should have explained more.

  1. Ultimately, I think that none of these names really make sense on their own and the user will need some familiarity with the documentation. I spent quite a while trying to come up with better names and didn't find anything compelling. I think that onType benefits from not carrying much information -- reducing the likelihood of misunderstanding it (they'll have to read the documentation) while paralleling the meaning of the matcher on and the behavior of thisPointerType (which also allows either the type or the pointer to that type).
  1. My particular concern with onOrPointsToType is that it sounds like the "or" applies to the on but it really means "on (type or points to type)".
alexfh added inline comments.Jan 28 2019, 8:00 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

So far, my observations are:

  1. three engineers quite familiar with the topic can't come up with a name that would explain the concept behind this matcher
  2. anyone reading that name would have to look up the documentation
  3. the implementation of the matcher is straightforward and even shorter than the documentation

Should we give up and let users just type on(anyOf(hasType(Q), hasType(pointsTo(Q))))?

If we want a bit more brevity here, maybe introduce a hasTypeOrPointsToType matcher (any bikeshed color will do ;) to shorten the expression above?

ymandel marked 2 inline comments as done.Jan 28 2019, 8:14 AM
ymandel added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

Yes to both suggestions (dropping this one and adding hasTypeOrPointsToType). It seems a rather obvious conclusion now that you've said it. :)

Personally, I'd go with hasOrPointsToType, but agreed that its just bike shedding. Aaron?

I'll drop this diff and create a new one for the new matcher.

aaron.ballman added inline comments.Jan 31 2019, 10:54 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

Personally, I'd go with hasOrPointsToType, but agreed that its just bike shedding. Aaron?

I think hasOrPointsToType is sufficiently clear within this context, but it makes me wonder if users are going to then need hasOrPointsToOrReferencesType() for other situations?

I am kind of leaning towards just letting users spell the matcher out long-hand as on(anyOf(hasType(Q), hasType(pointsTo(Q))))

ymandel marked 3 inline comments as done.Feb 15 2019, 6:53 AM
ymandel added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
3300 ↗(On Diff #182263)

Sure. I'll drop this revision and we can revisit in the future if we see sufficient demand.

ymandel abandoned this revision.Feb 15 2019, 6:54 AM
ymandel marked an inline comment as done.
ymandel updated this revision to Diff 190038.Mar 10 2019, 7:33 PM
This comment was removed by ymandel.
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2019, 7:33 PM
ymandel abandoned this revision.Mar 10 2019, 7:37 PM