This is an archive of the discontinued LLVM Phabricator instance.

Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions
ClosedPublic

Authored by eduucaldas on Jun 4 2020, 8:15 AM.

Diff Detail

Event Timeline

eduucaldas created this revision.Jun 4 2020, 8:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2020, 8:15 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
eduucaldas marked an inline comment as done.Jun 4 2020, 8:22 AM
eduucaldas added a subscriber: gribozavr2.
eduucaldas added inline comments.
clang/unittests/Tooling/Syntax/TreeTest.cpp
829

Perhaps we shouldn't differ between specifiers as that is semantical information

eduucaldas marked an inline comment as not done.Jun 4 2020, 8:22 AM
eduucaldas updated this revision to Diff 268503.Jun 4 2020, 9:19 AM
eduucaldas marked an inline comment as done.

.

clang/unittests/Tooling/Syntax/TreeTest.cpp
829

Followed the grammar, but added specifier in the end as we also hold the :: and not only the names

gribozavr2 added inline comments.Jun 4 2020, 9:49 AM
clang/unittests/Tooling/Syntax/TreeTest.cpp
815

This part does not seem to appear in the source.

eduucaldas updated this revision to Diff 269129.Jun 8 2020, 2:11 AM

cleanup for upstreaming

eduucaldas retitled this revision from Add support for id-expression in SyntaxTree to Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions.Jun 8 2020, 2:27 AM
eduucaldas edited the summary of this revision. (Show Details)
eduucaldas added a reviewer: gribozavr2.
gribozavr2 added inline comments.Jun 8 2020, 6:58 AM
clang/include/clang/Tooling/Syntax/Nodes.h
190 ↗(On Diff #269129)

Should there be getters for various parts of the specifier?

203 ↗(On Diff #269129)

Could you add more details? Feel free to even quote the relevant grammar bits.

211 ↗(On Diff #269129)

unqualified-id in the grammar can be more than one token.

212 ↗(On Diff #269129)

Could you swap the order of getters to match the source order?

clang/lib/Tooling/Syntax/BuildTree.cpp
618 ↗(On Diff #269129)

Do we need to mark the role if it is unknown?

clang/unittests/Tooling/Syntax/TreeTest.cpp
751

Could you add more tests even if they fail today due to missing implementation?

a::b::operator-(a::b::S())
a::b::S2<int>::f()

etc. Basically cover the whole grammar in tests, if possible.

eduucaldas marked 6 inline comments as done.Jun 9 2020, 12:24 AM
eduucaldas added inline comments.
clang/lib/Tooling/Syntax/BuildTree.cpp
618 ↗(On Diff #269129)

Thanks, that had slipped through, sorry for that

eduucaldas marked an inline comment as done.Jun 9 2020, 12:24 AM
eduucaldas edited the summary of this revision. (Show Details)
This comment was removed by eduucaldas.
eduucaldas updated this revision to Diff 269423.EditedJun 9 2020, 12:31 AM

Answering simple comments

gribozavr2 added inline comments.Jun 9 2020, 12:56 AM
clang/include/clang/Tooling/Syntax/Nodes.h
209 ↗(On Diff #269423)

Please add a TODO for the accessor for the 'template' keyword (and a test that has that keyword).

eduucaldas marked 7 inline comments as done.
  • cleanup for upstreaming
  • better coverage for unqualified-id
  • Better coverage for qualified-id
  • Finish implementing unqualified-id.
eduucaldas marked an inline comment as not done.Jun 18 2020, 2:35 AM
eduucaldas added inline comments.
clang/include/clang/Tooling/Syntax/Nodes.h
209 ↗(On Diff #269423)

I can implement accessor. But I couldn't write a test with this template keyword that uses DeclRefExpr. This is the test I came up with, note that both expressions are represented as DependentScopeDeclRefExpr

216 ↗(On Diff #269423)

Just by looking at code it is impossible to know if the accessed thing is optional or not.
IdExpression ALWAYS has a UnqualifiedId
IdExpression MAY have a NestedNameSpecifier
This same issue repeats in other places

190 ↗(On Diff #269129)

I think not.

Fix mistake on getting SourceRange for template-id

gribozavr2 added inline comments.Jun 18 2020, 3:46 AM
clang/include/clang/Tooling/Syntax/Nodes.h
187 ↗(On Diff #271620)

Could you provide examples or a grammar quote in the comment?

207 ↗(On Diff #271620)

"the size in std::vector<int>::size"

214 ↗(On Diff #271620)

Could you add TODOs about adding accessors?

clang/unittests/Tooling/Syntax/TreeTest.cpp
696

Could you split off the parts of this test that don't depend on C++11?

979

"WithTemplateKeyword"

1097

"QualifiedIdDecltype" for consistency with other tests.

1105

Indent -2?

1108

Could you indent the second line?

eduucaldas marked 12 inline comments as done.

Aswering comments

eduucaldas marked 2 inline comments as done.Jun 18 2020, 9:36 AM
eduucaldas added inline comments.
clang/include/clang/Tooling/Syntax/Nodes.h
214 ↗(On Diff #271620)

Pospone to interface discussion with Yitzhak

190 ↗(On Diff #269129)

Pospone to interface discussion with Yitzhak

clang/lib/Tooling/Syntax/Nodes.cpp
178 ↗(On Diff #271744)

I was thinking and our problem is bigger than not testing for NodeRoles, we don't test accessors at all!

182 ↗(On Diff #271744)

This should be an assert for now, as if that is not true it would be a logic problem. Same reasoning applies to CompoundStatement

gribozavr2 accepted this revision.Jun 18 2020, 10:13 AM
gribozavr2 added inline comments.
clang/lib/Tooling/Syntax/Nodes.cpp
182 ↗(On Diff #271744)

Yep, feel free to change it to an assert.

This revision is now accepted and ready to land.Jun 18 2020, 10:13 AM

change if -> asserts

This revision was automatically updated to reflect the committed changes.

@eduucaldas

Hi, you can drop Reviewers: Subscribers: Tags: and the text Summary: from the git commit with the following script:

arcfilter () {
        arc amend
        git log -1 --pretty=%B | awk '/Reviewers:|Subscribers:/{p=1} /Reviewed By:|Differential Revision:/{p=0} !p && !/^Summary:$/ {sub(/^Summary: /,"");print}' | git commit --amend --date=now -F -
}

Reviewed By: is considered important by some people. Please keep the tag. (I have updated my script to use --date=now (setting author date to committer date))

https://reviews.llvm.org/D80978 contains a git pre-push hook to automate this.