This is an archive of the discontinued LLVM Phabricator instance.

Propose naming principle for NodeRole and apply it
ClosedPublic

Authored by eduucaldas on Jun 4 2020, 6:34 AM.

Diff Detail

Event Timeline

eduucaldas created this revision.Jun 4 2020, 6:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2020, 6:34 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr2 added inline comments.Jun 4 2020, 7:10 AM
clang/include/clang/Tooling/Syntax/Nodes.h
94

I'd suggest to make this into a doc comment, but phrase it in a way that is useful for users, so that they can understand the pattern too. For example:

Some roles describe parent/child relations that occur multiple times in language grammar. We define only one role to describe all instances of such recurring relations. For example, grammar for both "if" and "while" statements requires an opening paren and a closing paren. The opening paren token is assigned the OpenParen role regardless of whether it appears as a child of IfStatement or WhileStatement node. More generally, when grammar requires a certain fixed token (like a specific keyword, or an opening paren), we define a role for this token and use it across all grammar rules with the same requirement. Names of such reusable roles end with a ~Token or a ~Keyword suffix.

Some roles are assigned only to child nodes of one specific parent syntax node type. Names of such roles start with the name of the parent syntax tree node type. For example, a syntax node with a role BinaryOperatorExpression_leftHandSide can only appear as a child of a BinaryOperatorExpression node.

140

Shouldn't elseKeyword have no prefix?

148–149

Shouldn't externKeyword have no prefix?

150–151

Shouldn't arrowToken have no prefix?

clang/lib/Tooling/Syntax/Nodes.cpp
128–129

Please update the textual representations of roles that you renamed, and reorder the switch to correspond to the new declaration order.

eduucaldas updated this revision to Diff 268502.Jun 4 2020, 9:13 AM
eduucaldas marked 2 inline comments as done.

Fix cout, add explanation

clang/include/clang/Tooling/Syntax/Nodes.h
94

Thank you a lot. This is really well explained

140

When a keyword can only be used by IfStatement, then I think it actually helps readability to have it prepended with the ParentKind. Here everything is nicely grouped, and if someone needs to change IfStatement, it is clear to see where to make the change.

gribozavr2 added inline comments.Jun 4 2020, 9:49 AM
clang/include/clang/Tooling/Syntax/Nodes.h
140

OK, makes sense.

ArrowToken, ExternKeyword

gribozavr2 added inline comments.Jun 4 2020, 10:14 AM
clang/include/clang/Tooling/Syntax/Nodes.h
110

There are some leftovers of old text after the period.

clang/lib/Tooling/Syntax/Nodes.cpp
155

Please reorder.

gribozavr2 accepted this revision.Jun 4 2020, 10:27 AM
This revision is now accepted and ready to land.Jun 4 2020, 10:27 AM
This revision was automatically updated to reflect the committed changes.