{"id":4393,"date":"2009-06-11T12:14:00","date_gmt":"2009-06-11T12:14:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2009\/06\/11\/call-hierarchy\/"},"modified":"2019-02-18T18:45:52","modified_gmt":"2019-02-18T18:45:52","slug":"call-hierarchy","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/call-hierarchy\/","title":{"rendered":"Call Hierarchy"},"content":{"rendered":"<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Hello everyone,<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">My name is Raman Sharma and I am a PM on the VC++ IDE team.&nbsp; I want to talk about a new feature called Call Hierarchy in Visual Studio 10.&nbsp; As the name suggests, it is used for navigating all functions <b>called from<\/b> within a particular function and all functions that make <b>calls to<\/b> a particular function.&nbsp; Many of you would know of a feature called Call Browser which was present in VC6, VS2005 and VS2008, and provided similar functionality.&nbsp; The Call Hierarchy feature is the revamped version of Call Browser, better organized and easier to use.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">In VS2010, Call Hierarchy has been designed such that it can be a shared feature for all languages i.e. the UI is common and different languages (like C#, C++ etc.) can fill the UI with their own data to address the semantic differences between the languages.&nbsp; For C#, this will be a new feature (See <\/font><a href=\"http:\/\/blogs.msdn.com\/kirillosenkov\/archive\/2009\/01\/10\/call-hierarchy-navigation-in-visual-studio-2010.aspx\"><font face=\"Calibri\" color=\"#0000ff\" size=\"3\">this post<\/font><\/a><font face=\"Calibri\" size=\"3\"> for more details).&nbsp; For C++, it is just about transitioning from the old Call Browser to Call Hierarchy to take advantage of the new design.&nbsp; <\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Let\u2019s look at an example that will illustrate the differences between the old functionality and the new one.&nbsp; Let\u2019s say you want to see the \u201ccalls from\u201d and \u201ccalls to\u201d information for two functions at the same time: <\/font><span>CImagingView::OnRButtonUp<\/span><span> <\/span><font face=\"Calibri\" size=\"3\">and<\/font><span> <\/span><span>CImagingView::OnContextMenu<\/span><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">In the previous releases, this would have effectively meant you having to open the following four call browser tool windows:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Call%20Hierarchy%201.png\"><\/p>\n<p class=\"MsoNormal\"><strong><font face=\"Calibri\" color=\"#4f81bd\">C++ Call Browser in VS2008<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">The above model clearly suffers from the following limitations:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">&#8211;<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">The \u201cCalls From\u201d and \u201cCalls To\u201d are presented in separate tool windows. (windows 1&amp;3 for Calls To and 2&amp;4 for Calls From)<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">&#8211;<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Each tool window can hold the call information for only one function at a time.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">&#8211;<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">The manner in which results are presented is not very intuitive:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">o<\/font><span>&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">In the window 2 above, the names of the functions called from <\/font><span>CImagingView::OnContextMenu <\/span><font face=\"Calibri\" size=\"3\">are listed at the bottom of the tree, whereas the actual calls to those functions are listed under the folder named <i>Calls from \u2018OnContextMenu\u2019<\/i>.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">o<\/font><span>&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">There is no link between the above two making navigation harder.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Let me just add, those windows would not be so neatly stacked together as I make them appear in the above screenshot.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">In VS2010 however, with the new Call Hierarchy feature, the same information is presented in one tool window in the following form:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Call%20Hierarchy%202.png\"><\/p>\n<p class=\"MsoNormal\"><strong><font face=\"Calibri\" color=\"#4f81bd\">C++ Call Hierarchy in VS2010<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Notice the following salient features in the above window:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">&#8211;<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">\u201cCalls From\u201d and \u201cCalls To\u201d trees for any function appear in the same place in one window.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">&#8211;<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">There can be multiple root nodes, thus obviating the need to open a separate window for each function. <\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">o<\/font><span>&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">The user can also right click on any non-root node in the tree and add it as a new root node to achieve better clarity.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">&#8211;<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">The results are much clearer to comprehend:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">o<\/font><span>&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">The tree in the left pane of the window will just show the names of the function (callers or callees) recursively.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">o<\/font><span>&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">When you click on a result in the left pane, the actual call site appears in the right pane.&nbsp; <\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">o<\/font><span>&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Upon double clicking the call-site in the right-pane, you are taken to that location in your source code in the Editor.&nbsp; <\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">&#8211;<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">The user can limit the search results to the current file, the current project or the entire solution for better filtering and performance.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">&#8211;<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">The user can copy the results from the call-sites pane and paste them elsewhere to perform some analysis.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">There was no way to do any of the above using the old Call Browser.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">The Call Hierarchy window can be invoked from the Editor context menu by just right-clicking on the function for which you want to see the results:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Call%20Hierarchy%203.png\"><\/p>\n<p class=\"MsoNormal\"><strong><font face=\"Calibri\" color=\"#4f81bd\">Call Hierarchy Invocation<\/font><\/strong><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">To build this feature, we have made use of the new C++ IDE infrastructure, the details of which were posted <\/font><a href=\"http:\/\/blogs.msdn.com\/vcblog\/archive\/2009\/05\/27\/rebuilding-intellisense.aspx\"><font face=\"Calibri\" size=\"3\">here<\/font><\/a><font face=\"Calibri\" size=\"3\"> recently.&nbsp; To populate the \u201ccalls from\u201d information for a function say <i>func<\/i>, we simply need to parse the contents of <i>func<\/i> and find out all the functions being called from within it.&nbsp; \u201cCalls To\u201d performs a wider search.&nbsp; A query is made to the SQL based database (explained <\/font><a href=\"http:\/\/blogs.msdn.com\/vcblog\/archive\/2009\/05\/27\/rebuilding-intellisense.aspx\"><font face=\"Calibri\" size=\"3\">here<\/font><\/a><font size=\"3\"><font face=\"Calibri\"> again) to find out all the locations where <i>func<\/i> is referenced, and then for all the results, their enclosing blocks of code are parsed to find out whether this reference actually is a function call to <i>func<\/i>.&nbsp; We have tried to make sure that the results we provide to you are accurate and complete.&nbsp; However, we don\u2019t claim to provide debugger-like accuracy.&nbsp; For example, you will not see implicit calls like destructors etc. being listed in the list of calls from a function (some day maybe<\/font><span>J<\/span><font face=\"Calibri\">).&nbsp; However, we have done enough to ensure that all the information relevant while designing, writing and reading code is available. &nbsp;<\/font><\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Overall, we believe that new intuitive user interface, greater flexibility, fewer navigation steps, and better accuracy make the new Call Hierarchy a very useful feature.&nbsp; We are excited about it and hope you will like it.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Thank you.<\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello everyone, My name is Raman Sharma and I am a PM on the VC++ IDE team.&nbsp; I want to talk about a new feature called Call Hierarchy in Visual Studio 10.&nbsp; As the name suggests, it is used for navigating all functions called from within a particular function and all functions that make calls [&hellip;]<\/p>\n","protected":false},"author":289,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[12,6],"class_list":["post-4393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-call-hierarchy","tag-ide"],"acf":[],"blog_post_summary":"<p>Hello everyone, My name is Raman Sharma and I am a PM on the VC++ IDE team.&nbsp; I want to talk about a new feature called Call Hierarchy in Visual Studio 10.&nbsp; As the name suggests, it is used for navigating all functions called from within a particular function and all functions that make calls [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/289"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=4393"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4393\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=4393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=4393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=4393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}