bloomberg / clangmetatool

A framework for reusing code in Clang tools
https://bloomberg.github.io/clangmetatool/
Apache License 2.0
119 stars 25 forks source link

`IncludeGraph::getData()` should return const pointer #70

Open liangti opened 2 years ago

liangti commented 2 years ago

Is your feature request related to a problem? Please describe.

Currently clients can fully access IncludeGraphData by IncludeGraph::getData() since it is returning a raw pointer.

It is volatile and then becomes stateful, so that may be easily misused.

Describe the solution you'd like

We should instead make IncludeGraph::getData() return const pointer.

So that IncludeGraphData can only be changed in frontend action and ppcallback, and becomes read-only toward clients.

The component that needs to modify IncludeGraphData should make a copy of it and take care of the lifetime of the copy themselves

Describe alternatives you've considered

Additional context

We should consider making all getData() return const pointer like this: https://github.com/bloomberg/clangmetatool/blob/master/include/clangmetatool/collectors/find_functions.h#L63

Because clang frontend action and ppcallback does not rely on those getData() to access data structures. Those data structures are passed by reference into callbacks

So getData() mostly are accessed by clients. And those data structures should be determined and unchanged once frontend compilation finished.