This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatchers] Add support for CXXRewrittenBinaryOperator
ClosedPublic

Authored by steveire on Jan 5 2021, 3:32 PM.

Diff Detail

Event Timeline

steveire requested review of this revision.Jan 5 2021, 3:32 PM
steveire created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2021, 3:32 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added inline comments.Jan 11 2021, 6:47 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
1998

Missing changes to Registry.cpp to expose this to clang-query?

5340

This change surprises me -- aren't rewritten binary operators *always* comparison operations? I don't know of a time when they'd ever be an assignment operator.

clang/lib/ASTMatchers/ASTMatchFinder.cpp
260

Please spell out this use of auto.

steveire marked an inline comment as done.Jan 14 2021, 3:23 PM
steveire added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
5340

Yes, which is why the new method in this patch on that class returns true.

This makes it possible to write

binaryOperation(isComparisonOperator())
binaryOperation(isAssignmentOperator())

(possibly with unless).

clang/lib/ASTMatchers/ASTMatchFinder.cpp
260

Please specify what to replace auto with when the replacement is a condition of acceptance.

Type noise makes code less readable, especially if the type contains <, > ,, spaces or :: or a combination of all of them. There is also ambiguity about what part of the type is a namespace, and what is an enclosing class etc. Very confusing,

In C++98 typedefs were often used to make that problem less bad.

The C++11 solution is auto.

So, you require that an auto must be replaced with something less optimal, please be specific about what you require it replaced with. I don't know what you want here, but my guess is it is a long type which makes the code less readable.

aaron.ballman accepted this revision.Jan 15 2021, 5:15 AM

LGTM aside from the auto usage.

clang/include/clang/ASTMatchers/ASTMatchers.h
5340

Ohhh, I see what the intent is now. Thank you for clarifying!

clang/lib/ASTMatchers/ASTMatchFinder.cpp
260

Please specify what to replace auto with when the replacement is a condition of acceptance.

If I knew that information, I would likely have not had to make the suggestion in the first place (or I would have suggested it as an edit). FWIW, I think it's a bit unreasonable to expect your code reviewers to hunt down the information you have at your fingertips as the code author (you presumably know what types your code edits are using).

From https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable:

"Don’t “almost always” use auto, but do use auto with initializers like cast<Foo>(...) or other places where the type is already obvious from the context."

There's nothing about this context that makes the type obvious to me. That said, I did the work and found the type should be spelled CXXRewriteBinaryOperator::DecomposedForm.

This revision is now accepted and ready to land.Jan 15 2021, 5:15 AM
This revision was landed with ongoing or failed builds.Jan 16 2021, 6:23 AM
This revision was automatically updated to reflect the committed changes.