This is an archive of the discontinued LLVM Phabricator instance.

[libTooling] Add stencil combinators for nodes that may be pointers or values.
ClosedPublic

Authored by ymandel on Nov 21 2019, 11:38 AM.

Details

Summary

Adds combinators maybeDeref and maybeAddressOf to provide a uniform way to handle
nodes which may be bound to either a pointer or a value (most often in the
context of member expressions). Such polymorphism is already supported by
access; these combinators extend it to more general uses.

Diff Detail

Event Timeline

ymandel created this revision.Nov 21 2019, 11:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 21 2019, 11:38 AM
gribozavr2 accepted this revision.Nov 22 2019, 2:36 AM
gribozavr2 added a subscriber: gribozavr2.
gribozavr2 added inline comments.
clang/include/clang/Tooling/Transformer/Stencil.h
101

Three slashes, please.

102

Need more explanation to cover the cases when the expression is a pointer to a pointer (do we deref once or twice?), or a smart pointer (do we take care of that at all?)

WDYT about calling it maybeDeref() or derefIfPointer()?

105

Three slashes, please.

107

Similarly, maybeAddressOf()?

This revision is now accepted and ready to land.Nov 22 2019, 2:36 AM
ymandel updated this revision to Diff 230646.Nov 22 2019, 7:04 AM

renamed combinators; reordered cases to pair x and maybeX.

ymandel marked 5 inline comments as done.Nov 22 2019, 7:08 AM

Thanks for the review!

clang/include/clang/Tooling/Transformer/Stencil.h
102

I went with maybe... Given that, I didn't elaborate on pointer-to-pointer case because it never claims to result in a value. WDYT?

also, I kind of like derefIfPointer better, but addressOfIfValue just seemed to clunky. So, went w/ maybe...

ymandel edited the summary of this revision. (Show Details)Nov 22 2019, 7:08 AM
Harbormaster completed remote builds in B41377: Diff 230647.
gribozavr2 accepted this revision.Nov 22 2019, 7:14 AM
gribozavr2 added inline comments.
clang/include/clang/Tooling/Transformer/Stencil.h
90

"If the expression \p ExprId has pointer type ..."

101

"If the expression \p ExprId is not a pointer, ..."

gribozavr2 marked an inline comment as done.Nov 22 2019, 7:15 AM
gribozavr2 added inline comments.
clang/include/clang/Tooling/Transformer/Stencil.h
102

Given that, I didn't elaborate on pointer-to-pointer case because it never claims to result in a value. WDYT?

I think it is clear what happens with pointers to pointers given the current doc comment.

This revision was automatically updated to reflect the committed changes.
ymandel marked an inline comment as done.