This is an archive of the discontinued LLVM Phabricator instance.

[SyntaxTree] Unbox operators into tokens for nodes generated from `CXXOperatorCallExpr`
ClosedPublic

Authored by eduucaldas on Aug 11 2020, 9:36 AM.

Details

Summary

For an user define <, x < y would yield the syntax tree:

BinaryOperatorExpression
|-IdExpression
| `-UnqualifiedId
|   `-x
|-IdExpression
| `-UnqualifiedId
|   `-<
`-IdExpression
  `-UnqualifiedId
    `-y

But there is no syntatic difference at call site between call site or
built-in <. As such they should generate the same syntax tree, namely:

BinaryOperatorExpression
|-IdExpression
| `-UnqualifiedId
|   `-x
|-<
`-IdExpression
  `-UnqualifiedId
    `-y

Diff Detail

Event Timeline

eduucaldas created this revision.Aug 11 2020, 9:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2020, 9:36 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
eduucaldas requested review of this revision.Aug 11 2020, 9:36 AM

Add explanation comments

eduucaldas added inline comments.
clang/lib/Tooling/Syntax/BuildTree.cpp
1025

Here we want to check if this child is just a DeclRefExpr to an operator - as opposed to an operand.
Is comparing SourceLocation generally safe?
Is there a better way of figuring out if the child DeclRefExpr refers to an operator?

gribozavr2 accepted this revision.Aug 11 2020, 10:11 AM
gribozavr2 added inline comments.
clang/lib/Tooling/Syntax/BuildTree.cpp
1017–1018
1023–1029
This revision is now accepted and ready to land.Aug 11 2020, 10:11 AM
gribozavr2 added inline comments.Aug 11 2020, 10:18 AM
clang/lib/Tooling/Syntax/BuildTree.cpp
1025

Comparing SourceLocations should work, but you're right that it is a questionable pattern.

Iterating only over S->arguments() instead of all children could work here.

eduucaldas marked 3 inline comments as done.

use arguments instead of children

clang/lib/Tooling/Syntax/BuildTree.cpp
1025

Very good tip!