This is an archive of the discontinued LLVM Phabricator instance.

[clang] Provide a better pretty-printed name for unnamed parameters, lambda classes and lambda captures.
AcceptedPublic

Authored by riccibruno on Jul 31 2020, 8:54 AM.

Details

Summary

As a follow up to D84658:

For an unnamed parameter: (unnamed variable at {{.*}}:<line>:<col> of type <type>) -> (unnamed parameter at {{.*}}:<line>:<col> of type <type>).

For a lambda class: (unnamed class at {{.*}}:<line>:<col>) -> (lambda at {{.*}}:<line>:<col>).

For an unnamed field representing a capture: (unnamed field at {{.*}}:<line>:<col> of type <type>) -> pretty-printed name of the captured variable (except for now in the uncommon case of a captured VLA bound; see the comment).

Additionally add some unit tests for the changes in this patch and in the previous D84658.

Diff Detail

Event Timeline

riccibruno created this revision.Jul 31 2020, 8:54 AM
riccibruno retitled this revision from [clang] Provide a better name for unnamed parameters, lambda classes and lambda captures. to [clang] Provide a better pretty-printed name for unnamed parameters, lambda classes and lambda captures..Jul 31 2020, 9:24 AM
riccibruno edited the summary of this revision. (Show Details)

Make the unit tests in NamedDeclPrinterTest.cpp more robust.

Add -fno-delayed-template-parsing to the new unit tests to also pass on Windows.

riccibruno edited the summary of this revision. (Show Details)Jul 31 2020, 2:52 PM
riccibruno updated this revision to Diff 282391.Aug 1 2020, 5:33 AM
riccibruno edited the summary of this revision. (Show Details)

Don't forget to increment the field iterator in the loop of maybePrintFieldForLambdaCapture, and modify the tests to test this.

aaron.ballman accepted this revision.Aug 5 2020, 4:23 AM

LGTM aside from a minor nit.

clang/lib/AST/Decl.cpp
2129

Rather than isa<> followed by a cast<>, how about:

if (const auto *FD = dyn_cast<FieldDecl>(DD)) {
  if (maybePrintFieldForLambdaCapture(...)
    return;
}

Alternatively, you could sink the dyn_cast<> down into maybePrintFieldForLambdaCapture() since that already has to handle case where it's not printing a field capture.

This revision is now accepted and ready to land.Aug 5 2020, 4:23 AM