Visual C++ Code Model

Visual C++ Code Model

  • Comments 10

Hi, my name is Vytautas Leonavičius, and I'm recent addition to VC++ IDE dev team. My focus areas are VC Wizards and VC++ Code Model (CM). Today, I’d like to talk about future of the CM.

In a sentence (actually, two sentencesJ), the VC++ CM is a collection of classes that allows a client to get source code reflected in objects. Objects have read and write properties, so, for example, VCCodeClass.Name allows you to get the name of the class. It also allows you to rename a class by assigning a different value to Name property. More on the VC++ CM can be found in MSDN: http://msdn2.microsoft.com/en-us/library/t41260xs(VS.80).aspx

The VC++ CM is used by various Visual Studio components. In particular, VC++ Wizards and Class Designer use it. Such an architecture greatly simplifies those components by deferring source code manipulations to the CM.

Currently C++ Intellisense, Class View, CM and other components use the NCB as an underlying database. As Jason mentions in his post http://blogs.msdn.com/vcblog/archive/2006/08/16/thoughts-on-the-visual-c-abstract-syntax-tree-ast.aspx , in VC10, we’re moving to a new architecture. We’re expecting to improve the following aspects of CM:

·         As CM is based on NCB today, it has to do additional C++ code parsing. This is primarily caused by a limitation of NCB architecture, where no column information is provided for source code elements (a C++ program can be written in one line). The new architecture will provide column information. Methods doing a lot of text processing, like VCCodeElement.StartPointOf, will become faster.

·         The NCB had not been originally designed to support templates and namespaces. Although NCB supports both today, the support is far from perfect. That causes processing overhead in the VC++ CM and various correctness issues. The new architecture is designed from scratch and takes into account modern C++ coding realities.

·         The NCB contains a snapshot of source code in one macro state. That means, if we have code like:

#define X

 

#ifdef X

class A {};

#else

class B {};

#endif

only class A will make it to NCB. The new architecture is based on different principles. The database will contain both definitions and the CM will be able to provide a true reflection of source code in this scenario.

·         VCCodeElement.CodeElementFromFullName/ VCCodeElement.CodeTypeFromFullName will support wildcards.

·         We expect VCCodeModel.Synchronize to become faster, because population of the underlying database is going to be based on different principles than it is today.

The VC++ team is looking forward to hear your feedback. Any suggestions, comments and feedback about what we can do to make VC++ Code Model better are welcome.

Vytas/Visual C++

 

  • How does this handle more advanced preprocessor definitions?

    For example:

    testheader.hpp:

    #ifdef X

    class A {};

    #else

    class B {};

    #endif

    first.cpp:

    #define X

    #include "testheader.hpp"

    second.cpp:

    #undef X

    #include "testheader.hpp"

    And that's just the simple example; it's not even getting into the boost preprocessor metaprogramming library.

  • In current architecture, each file is processed once. So depending on which .cpp file gets processed first, you will get only definition of A or B in NCB database. This is known limitation of current architecture.

    In new architecture, we expect to provide true source code reflection. So both A and B should be visible no matter which macro state they’re encountered in.

    You can easily observe current behavior by using ClassView window.

    Vytas/Visual C++

  • Great, it looks promising. I had noticed that intellisense used to work well without namespaces but that it gets progressively worse when we add namespaces and templates to the project. So, that's the reason.

    One small improvement that i would like to see is  wizards that are aware of indent settings. If my tab/indent settings are not the default (e.g., indent always with 2 spaces, tabstop 8), the generated code looks awful.

    With a comprehensive Code Model, i think it would be possible to go back to the Wizard and change some options even after the project has been generated, right?

  • "Reflection" API.

    We internally use BSC toolkit for auto-generating persistance code which can dump program settings into a database. We create browse info for 1 cpp file which includes all required headers. This is done from command line and it does not depend on whether linker optimizes out these classes with netadata from the assembly. It happens with my attempts to use /clr switch and System.Reflection.

    As I can see, BSC toolkit is not supported anymore so I began thinking about new ways to reflect on C++ data types. I hope new Code Model will provide an API which is accessible from command line.

  • Side question about that, are some code formatting settings coming with this (i.e. where I want my braces etc.)? I'd like to auto-generate code with this (looks really good so far), but I don't want to have to reformat it to my coding guidelines ... any chance something like Netbeans/Eclipse has for code formatting will make its way into VS?

  • Anonymous wrote:

    "are some code formatting settings coming with this (i.e. where I want my braces etc.)? I'd like to auto-generate code with this (looks really good so far), but I don't want to have to reformat it to my coding guidelines"

    We are still in the planning phase for VC10 and as Vytas mentioned, we are interested in your feedback. A more advanced code beautifier in the C++ editor (and a CodeModel conforming to its rule) is a great suggestion. Thanks.

    ikk wrote:

    "With a comprehensive Code Model, i think it would be possible to go back to the Wizard and change some options even after the project has been generated, right?"

    Agree, with a more sound implementation of CM, any wizard can more reliably change the code that it previously created. We have this today for some wizards (mostly event handlers wizards). Even if we don't have plans to re-architect the project wizards or class wizards in VC10 for such support, 3rd party wizards can definitely take advantage of CM and consider this user-friendly approach.

    Marian Luparu

    Visual C++ IDE

  • Please tell my how i can get back my Visual Stuido 2005 C++ startpage in englisch.

    It changeged now for whatever reason to a new URL (http://go.microsoft.com/fwlink/?linkid=45332&clcid=407) that has a lot of uninteresting german news. I liked the other one much better. It had news from the C++ Center of msdn.

  • You want to change the URL in Tools > Option > Environment > Startup > news channel : http://go.microsoft.com/fwlink/?linkid=45332&clcid=409. You can also use http://blogs.msdn.com/vcblog/rss.xml if you like :)

    Marian Luparu

    Visual C++ IDE

    PS: Pat, in the future, please direct these questions to the forums. Thanks. http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1015&SiteID=1

  • Hi,

    I think that code "beutification", or re-formatting, is simply a must, and it should be very customizable. Just look at what you can set up in, say, IntelliJ Idea. I can't believe that this is not available in VC! In fact, moving from 6.0 to 2005 is a step back in terms of indenting. I want to set up the looks of my functions, switches, classes etc. and do a one-keystroke reformat of the whole source code. This is what people do all the time in other IDEs and I just spend quite a lot of time doing this manually, because the builtin formatter would ruin all my efforts. Maybe I could save the file and run it through vi or emacs? :-)

    Cheers,

    Filip

  • Hi,

    Im am interested in writing a source code analysis add-in, would the code model be useful for this purpose.

    Thanks

    Ed

Page 1 of 1 (10 items)