This is an archive of the discontinued LLVM Phabricator instance.

[clang][AST][NFC] Move isSubstitutedDefaultArgument out of TypePrinter into separate component
ClosedPublic

Authored by Michael137 on Dec 13 2022, 5:50 PM.

Details

Reviewers
aprantl
dblaikie
Summary

A use-case has come up in DWARF CodeGen where we want to determine
whether a particular template argument matches the default template
parameter declaration.

Re-using this TypePrinter component there allows us to avoid duplicating
most of this code and immediately allows us to cover a wider range
of use-cases than the DWARF CodeGen does today.

Diff Detail

Event Timeline

Michael137 created this revision.Dec 13 2022, 5:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 5:50 PM
Michael137 requested review of this revision.Dec 13 2022, 5:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 5:50 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Seems fine to me, I just have one inline comment about the name of the namespace.

clang/include/clang/AST/TemplateUtils.h
19 ↗(On Diff #482676)

It looks like all the other namespaces in Clang are all lowercase?

dblaikie added inline comments.
clang/include/clang/AST/TemplateUtils.h
19 ↗(On Diff #482676)

Yeah, +1 to the naming.

& maybe not introducing a new "utils" bucket - they can be a bit of a dumping ground. Could this operation belong elsewhere/in some existing type, or maybe doesn't need a namespace wrapper - could be a free function in the clang namespace?)

clang/lib/AST/TemplateUtils.cpp
19 ↗(On Diff #482676)

The LLVM style is to use static for file-local functions, only using anonymous namespaces for file-local classes ( https://llvm.org/docs/CodingStandards.html#anonymous-namespaces )

144–148 ↗(On Diff #482676)

Could probably remove these "else after return"s while you're moving this code if you like.

Michael137 added inline comments.Dec 15 2022, 5:33 AM
clang/include/clang/AST/TemplateUtils.h
19 ↗(On Diff #482676)

I suppose this could just be a static function on clang::TypePrinter. We use it from CGDebugInfo already anyway so it wouldn't be an extra dependency. Wdyt? @aprantl @dblaikie

Michael137 marked 2 inline comments as done.Dec 15 2022, 6:39 AM
aprantl added inline comments.Dec 15 2022, 11:50 AM
clang/include/clang/AST/TemplateUtils.h
19 ↗(On Diff #482676)

I don't have any strong opinions either way.

dblaikie added inline comments.Dec 15 2022, 12:38 PM
clang/include/clang/AST/TemplateUtils.h
19 ↗(On Diff #482676)

Sounds good to me.

  • Don't create separate component. Instead move API into Type.h
dblaikie accepted this revision.Dec 15 2022, 2:26 PM

Looks good, thanks!

This revision is now accepted and ready to land.Dec 15 2022, 2:26 PM
Michael137 added a comment.EditedDec 16 2022, 3:49 AM

committed in 98afcbab66505661045dccb85ee9acdbf9410047 (https://reviews.llvm.org/rG98afcbab6650)
Missed phab link in commit message

Michael137 closed this revision.Dec 16 2022, 3:49 AM