This is an archive of the discontinued LLVM Phabricator instance.

[formatters] Add a libstdcpp formatter for forward_list and refactor list formatter
ClosedPublic

Authored by danilashtefan on Nov 7 2021, 1:13 AM.

Details

Summary

This diff adds a data formatter for libstdcpp's forward_list. Besides, it refactors the existing code by extracting the common functionality between libstdcpp forward_list and list formatters into the AbstractListSynthProvider class.

Diff Detail

Event Timeline

danilashtefan requested review of this revision.Nov 7 2021, 1:13 AM
danilashtefan created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 7 2021, 1:13 AM
danilashtefan retitled this revision from Summary: to [formatters] Add a libstdcpp formatter for forward_list and refactor list formatter.Nov 7 2021, 1:22 AM
danilashtefan edited the summary of this revision. (Show Details)
danilashtefan added a reviewer: wallace.

Hi Walter:) Please, could you advise what can I change/do more? As a next step, I will unify the tests across the libcxx and libstdcpp formatters.

wallace requested changes to this revision.Nov 7 2021, 10:20 AM

very good start!

lldb/examples/synthetic/gnu_libstdcpp.py
5–6

remove this

21–151

remove all these _abstract suffixes. They make reading harder

27

here you should call the method get_end_of_list_address that i mention below

41–42

don't remove this command. It's useful to know what's going on

95

what is this? try to come up with a better name with documentation to make this easier to understand

161

don't pass the is_valid_break_condition variable everywhere. It makes code more confusing. Instead, you should create a method "get_end_of_list_address" that should be overridden by each child implementation. Then you add a comment that this address is used to identify if a node traversal has reached its end

161

don't pass 'type' here, instead, in the constructor of the parent in line 158 pass a boolean flag 'has_prev'. That should be enough for the parent class to know if there's a prev pointer or not

161

similarly, pass incoming_size to the constructor, and a better name is "node_value_pointer_offset", and you add a comment explaining that lists have 1 or more pointers followed by the value

This revision now requires changes to proceed.Nov 7 2021, 10:20 AM
danilashtefan marked 8 inline comments as done.

All of the requested changes are done. Please, let me know if any other corrections are needed

wallace requested changes to this revision.Nov 8 2021, 11:36 PM

Much better. Just some better patterns that you could follow. Read my comments.

Besides that, now you can unify the tests across libcxx and libstdcpp

lldb/examples/synthetic/gnu_libstdcpp.py
15–17

Add these comments and remove the node_value_pointer_offset, as it can be inferred from has_prev

19

remove

68–69

remove this trailing space

82–88

nice

89

let's better initialize this with a simpler value

95–96

remove this or do any necessary corrections here

120–122
154–157

good

164–167

remove

170–177

you can delete these

179–183

instead of this, declare a method in the parent class

def updateNodes(self)
  ... # don't return anything

that is invoked by 'update'.
both children must implement this method. That way you don't need to invoke super. Also you should write a comment that the 'udpateNodes' method must give value to self.node and self.next, and optionally to self.prev

194–197

remove

This revision now requires changes to proceed.Nov 8 2021, 11:36 PM
danilashtefan marked 10 inline comments as done.

All the requested changes are done :)

danilashtefan added inline comments.Nov 9 2021, 2:18 AM
lldb/examples/synthetic/gnu_libstdcpp.py
89

Initial size does also depend on the has_prev value, so I decided to initialize it is this simple way

95

Size to return also depends on the has_prev. I have simplified the previously introduced if case

Right size is returned and tests are unified! :)

wallace accepted this revision.Nov 9 2021, 11:13 AM

thanks!

This revision is now accepted and ready to land.Nov 9 2021, 11:13 AM