This is an archive of the discontinued LLVM Phabricator instance.

[Syntax] Build declarator nodes
ClosedPublic

Authored by ilya-biryukov on Jan 2 2020, 8:32 AM.

Details

Reviewers
gribozavr2
Summary

They cover part of types and names for some declarations, including
common cases like variables, functions, etc.

See the comment of Declarator for more details.

Diff Detail

Event Timeline

ilya-biryukov created this revision.Jan 2 2020, 8:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 2 2020, 8:32 AM

Unit tests: unknown.

clang-tidy: unknown.

clang-format: unknown.

Build artifacts: diff.json, console-log.txt

  • Rebase, get rid of accidental changes with TemplateDeclaration

Unit tests: pass. 61848 tests passed, 0 failed and 781 were skipped.

clang-tidy: unknown.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

gribozavr2 added inline comments.Jan 16 2020, 7:05 AM
clang/include/clang/Tooling/Syntax/Nodes.h
395

s/iterator/container/ ?

Also unclear why a custom one should be used.

I also think it should be an implementation comment (in the .cc file).

491

Also [static 10] in void f(int xs[static 10]);

500

+ TODO: add an accessor for the "static" keyword.

503

s/inside parameter list/after the parameter list/ ?

s/starting from/starting with/ or "including the arrow token" to emphasize that the arrow is included.

512

+ TODO: add accessors for specifiers.

Or we could add a syntax node for the "type-id" construct -- it seems like it will be useful in other places that require exactly one type, like the argument of sizeof, type argument of static_cast etc. (Also could be a TODO, this patch is pretty long.)

515

Would be great to show an example of what sort of qualifiers we're talking about here (trailing "const", "volatile", "&", "&&", right?) What about "noexcept"? Would be also good to say that "override" does not belong here.

524

Similarly, I think it should be an implementation comment.

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

A brief comment about why this is necessary (and why it works) would be appreciated. Just remind the reader that type locs are stored inside-out, and that the start location in the source order would be on the innermost node.

119

Why don't we need a similar visitor to get the end location? I think we have a similar inside-out problem with int x[10][20].

306

The past tense in Executed threw me off -- I thought that we already executed these folds, and now doing them again for some reason.

Consider BeginFolds / EndFolds?

483

Looks like this patch was not updated for https://reviews.llvm.org/D72446 (because we're not passing the AST node to markChild)?

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

I think we already have one of these tests for static_assert.

931

Now that this test is going over 1000 lines, I'd really appreciate splitting it into multiple files, each focusing on one aspect (e.g., one file for testing declarators). Could be a follow-up change.

1210

A few complex tests that combine multiple declarators would be nice (especially to test that the delayed fold logic composes correctly).

char (*(*x[10])(short a, int b))[20];
char (*(*x[10][20])(short a, int b))[30][40];
void x(char a, short (*b)(int));
void x(char a, short (*b)(int), long (**c)(long long));
void (*x(char a, short (*b)(int)))(long);

Also qualifiers -- or are they not implemented yet?

int * const * volatile x;
hlopko added a subscriber: hlopko.Mar 16 2020, 3:27 AM

I'm taking over of this patch (with a kind permission from Ilya :) I've replied to comments here, but let's continue the review over at https://reviews.llvm.org/D76220. Thanks :)

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

Waiting for reply from Ilya offline, in the meantime I'm keeping the comment as is.

491

Added example into the comment + added a test verifying it's handled correctly.

500

Added a TODO.

503

Done.

512

Added a TODO (also mentioning type-id node)

515

Added a comment (and added tests where there was no coverage):

+/ E.g.:
+
/ (volatile int a) in int foo(volatile int a);
+/ (int&& a) in int foo(int&& a);
+
/ () -> int in auto foo() -> int;
+/ () const in int foo() const;
+
/ () noexcept in int foo() noexcept;
+/ () throw() in int foo() throw();
+
/
+/// (!) override doesn't belong here.

524

Will handle once I hear from Ilya.

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

Added:

53 / Get start location of the Decl from the TypeLoc.
54
/ E.g.:
55 / loc of ( in int (a)
56
/ loc of * in int *(a)
57 / loc of the first ( in int (*a)(int)
58
/ loc of the * in int *(a)(int)
59 / loc of the first * in const int *const *volatile a;
60
/
61 / (!) TypeLocs are stored inside out (in the example above *volatile is
62
/ the TypeLoc returned by Decl.getTypeSourceInfo(), and *const is
63 /// what .getPointeeLoc() returns.

119

Could you elaborate? I added a test for `int a[1][2][3] and it seems to be working correctly?

306

Used BeginFolds/EndFolds.

483

I plan to submit declarator nodes patch, then template nodes patch, then https://reviews.llvm.org/D72446. So this comment will be handled by that patch.

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

Removed once copy.

931

Will happily do in a separate patch.

1210

Some of these tests actually crash, so I'll debug/fix in a separate patch.

gribozavr2 added inline comments.Mar 16 2020, 6:38 AM
clang/unittests/Tooling/Syntax/TreeTest.cpp
1210

BTW, would be also nice to have trailing return types not at the top level:

auto x(char a, auto (*b)(int) -> short) -> void;

This revision is now accepted and ready to land.Mar 16 2020, 11:15 AM
gribozavr2 closed this revision.Mar 16 2020, 11:15 AM