This is an archive of the discontinued LLVM Phabricator instance.

[Syntax] Build mapping from AST to syntax tree nodes
ClosedPublic

Authored by hlopko on Mar 18 2020, 5:42 AM.

Details

Summary

Copy of https://reviews.llvm.org/D72446, submitting with Ilya's permission.

Only used to assign roles to child nodes for now. This is more efficient
than doing range-based queries.

In the future, will be exposed in the public API of syntax trees.

Diff Detail

Event Timeline

hlopko created this revision.Mar 18 2020, 5:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2020, 5:42 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
hlopko edited the summary of this revision. (Show Details)Mar 18 2020, 5:44 AM
hlopko updated this revision to Diff 251603.Mar 20 2020, 4:04 AM

Addressing comments.

hlopko updated this revision to Diff 251968.Mar 23 2020, 2:30 AM

Reformat

gribozavr2 added inline comments.Mar 23 2020, 2:58 AM
clang/lib/Tooling/Syntax/BuildTree.cpp
173

The comment is not needed anymore.

489

Could you add a private setter that performs this cast? (The cast is repeated at least 3 times in this patch.)

571

It might make sense to add a helper Builder.getRange(SourceRange) and simplify these calls to Builder.getRange(something.getBegin(), something.getEnd()) throughout the patch.

976

Add a Decl *From parameter and pass it through to Builder.foldNode() below?

hlopko updated this revision to Diff 251993.Mar 23 2020, 4:58 AM
hlopko marked 6 inline comments as done.

Address comments

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

Done and refactored all the calls that made sense to use the SourceRange method. I didn't modify call like Builder.getRange(L.getLBracketLoc(), L.getRBracketLoc()).

976

Done, but to get rid of all nullptr parents in BuildTree.cpp we'd have to implement support for Types in the AST mapping. Let's not do that in this patch.

gribozavr2 added inline comments.Mar 23 2020, 7:51 AM
clang/include/clang/Tooling/Syntax/Tree.h
129

setRole() (in new code).

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

Don't repeat the function name in comments.

/// Finds the syntax tokens that correspond to the provided \c SourceRange.

266

Ditto.

976

For consistency with, for example, foldTemplateDeclaration, I think Decl *From should be the last parameter.

hlopko updated this revision to Diff 252045.Mar 23 2020, 8:01 AM
hlopko marked 5 inline comments as done.

Address comments

PTAL.

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

Clang tidy complains when I remove it :/

gribozavr2 accepted this revision.Mar 23 2020, 8:04 AM
This revision is now accepted and ready to land.Mar 23 2020, 8:04 AM
This revision was automatically updated to reflect the committed changes.