[Qt-creator] Virtual functions resolving

Verbruggen Erik Erik.Verbruggen at digia.com
Thu Nov 22 11:16:13 CET 2012

On Nov 20, 2012, at 21:29, Orgad Shaneh <orgads at gmail.com> wrote:

> 0. Currently Find Usages mixes usages (references) with declarations. This is mostly useful for renames. When users (at least me and some people I asked :)) look for usages, they usually are not interested in declarations. To address this, I suggest adding a combobox in the C++ Usages search pane that will filter 'Declarations', 'Usages' or 'All'. The pane could be renamed respectively (C++ References? C++ Symbols?)


> 1. Conceptually, when users call Find Usages, they want to know which calls can reach this piece of code. For virtual functions, calls to 'lower' (i.e. more concrete) types which implement the function, will not reach the function in 'higher' types.
> For example, Find Usages on Base::v (usages only, we'll leave declarations for later) should only list entries 4 and 5 and 6. 7 is not calling Base::v since it is reimplemented in MostDerived.

I think this is a cool idea. A bit of background: when we implemented this feature, we did have some discussion on what to  show, mostly regarding overloads/overrides, but wanted to make sure that a user would not get confused too much (otherwise they would always choose the "gimme all stuff" option anyway). What also helped was that the current implementation just happens to give us the rename feature for free. So a warning up-front: when changing find-usages, keep one code-path there to be used with the renaming.

I don't have a strong opinion (yet) on the UI, so we'll see when it gets there.

About the implementation: no, you wouldn't need to rewrite much of libcplusplus :) Off the cuff, I would have all the results calculated in the future (see CppFindReferences::findAll_helper), and filter it afterwards (so you don't need to restart the search). You'll probably need to extend CPlusPlus::Usage to record the type of usage though. Most other logic goes into CPlusPlus::FindUsages.

> 2. Follow Symbol has complementary behavior. Conceptually, following a symbol means 'where will this call lead?'. Again, for virtual functions the answer is complex, since a call for a basic type can lead to a more concrete type.
> For example, Follow Symbol on entries 5 or 6 (here referring to declarations) should list entries 2 and 3, but not 1, since a call to Base, which implements v() itself, can not lead to MostBasic.
> To address this, I suggest adding a new action which will open a C++ Usages search pane with declarations only, containing only relevant entries.

I hope I read it correctly that you don't want to replace the current follow-symbol functionality? :) If so, sounds good!

Erik Verbruggen
Senior Software Engineer
Digia, Qt

Digia Germany GmbH
Rudower Chausse 13, 12489 D-Berlin
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B,  
Geschäftsführer: Mika Pälsi, Juha Varelius, Anja Wasenius
Email: erik.verbruggen at digia.com 
Qt Blog: http://blog.qt.digia.com/
Qt Facebook: www.facebook.com/qt 
Qt Twitter: www.twitter.com/qtcommercial 

Digia Germany is a group company of Digia Plc, 
Valimotie 21, FI-00380 Helsinki Finland
Visit us at: www.digia.com 

More information about the Qt-creator mailing list