This is an archive of the discontinued LLVM Phabricator instance.

[SyntaxTree][NFC] Refactor function templates into functions taking base class
ClosedPublic

Authored by eduucaldas on Aug 27 2020, 8:41 AM.

Details

Summary

The refactored functions were

  • isReponsibleForCreatingDeclaration
  • getQualifiedNameStart

Diff Detail

Event Timeline

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

Inline getDeclaratorRange inside buildTrailingReturn

eduucaldas added a reviewer: gribozavr2.EditedAug 27 2020, 9:43 AM

As a result of this change getDeclaratorRange is used exclusively inside processDeclaratorAndDeclaration and the last two arguments are direct results of getQualifiedNameStart(D) and getInitializerRange(D), which are used exclusively in this context.

Perhaps we should inline getQualifiedNameStart and getInitializerRange and make getDeclaratorRange a member function taking a Decl. What do you think?

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

I would argue that this is much clearer :)

1472–1473
  1. TrailingReturn is not a Declarator
  2. Inlining the arguments is actually less code and much than using the getDeclaratorRange here.
gribozavr2 accepted this revision.Aug 27 2020, 11:53 AM

Perhaps we should inline getQualifiedNameStart and getInitializerRange and make getDeclaratorRange a member function taking a Decl. What do you think?

These helpers seem to have well-defined semantics, so I'd rather keep them separate. If anything, I'd make helpers into free functions to emphasize that they don't use the class member variables and are standalone functions.

This revision is now accepted and ready to land.Aug 27 2020, 11:53 AM

Move getDeclaratorRange helpers outside of TreeBuilder
Add coverage for qualified declarators and init-declarators

eduucaldas added inline comments.Aug 28 2020, 2:29 AM
clang/lib/Tooling/Syntax/BuildTree.cpp
225–226

I followed the grammar to get these and also added tests for them.

245

There was no problem with the declarator of operator+ should I remove this?
Also I really tried to break it ^^.

I think though perhaps this is going to bite us in an obscure way, so I would just remove the e.g. ....

gribozavr2 accepted this revision.Aug 28 2020, 4:05 AM
gribozavr2 added inline comments.
clang/lib/Tooling/Syntax/BuildTree.cpp
202
245

Feel free to remove the fixme.

What do you mean by "remove the e.g. ..."? Removing the examples from the comment? Why?

eduucaldas marked an inline comment as done.

Rebase and answer comments

eduucaldas marked an inline comment as done.Aug 28 2020, 5:18 AM
eduucaldas added inline comments.
clang/lib/Tooling/Syntax/BuildTree.cpp
245

I meant

/// FIXME: \p Name must be a source range, e.g. for `operator+`.

->

/// FIXME: \p Name must be a source range.
gribozavr2 accepted this revision.Aug 28 2020, 5:23 AM
This revision was landed with ongoing or failed builds.Aug 28 2020, 5:25 AM
This revision was automatically updated to reflect the committed changes.
eduucaldas marked an inline comment as done.