SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Siegfried Pammer

ILSpy and VB: A Brief Insight Into the Whys and Hows

There have been some requests for adding additional output languages to ILSpy in the past few days. Besides C# there are lots of .NET languages and every developer uses his/her preferred language(s). On the team we're using (almost) only C#. From our point of view there is no urgent need for supporting other output languages. But we know that there are people out there, waiting for other languages in ILSpy. So, which language should be the next?

We picked VB .NET and the reason's quite clear: VB has a huge user base and is widely used.

As you may know, in ILSpy we are using a new NRefactory for AST transformations, analysis and to output C# code. This version is referred to as "NRefactory 5". It is a complete rewrite of the old NRefactory with improved parsers, AST and also contains an implementation of a type system, that will be used for various features in upcoming versions of SharpDevelop.

Let me emphasize: It is a rewrite, thus there are still some things to be done or broken. There's also some code of the VB counterpart of C# AST and parser in NRefactory.VB. Right now, I am working on porting the old VB parser and AST to the new NRefactory and I will push some updates from time to time.

How will it be done?

The basic idea of implementing VB output support in ILSpy is the following:

 

In most parts C# and VB are very similar. Therefore, it would make no sense to reinvent the wheel, and redo all the hard work Daniel and David did while implementing support for C#. The C# AST will be converted to VB AST and then we will do some transformations needed to produce nice-looking VB code. Examples for such transformations would be: convert pointers in unsafe code (which is not supported in VB) to IntPtr, or another: use the VB With statement where it makes sense.

Does not seem to be that much work? As I already mentioned, the whole VB AST needs to be ported and extended. More specifically, it will be rewritten almost from scratch, because the old AST was a mixture of C# and VB syntax and did not contain all information needed for advanced features and tools like ILSpy or refactorings in the IDE.

So, here's a (surely incomplete) list of things that need to be done to add VB output support to ILSpy:

  • Implement the AST for VB
  • Create an output visitor (pretty printer) for VB
  • Create a C#->VB AST converter
  • Implement AST transforms to make the code look nicer

When will it be done?

Once I get something done, I will explain the different parts more in detail. Unfortunately, I am currently in exam cram mode, so do not expect anything for the next month.

Published Apr 28 2011, 08:30 PM by siegi44
Filed under: ,

Comments

 

Josch said:

Is it not possible to simply use and maybe extend the C#->VB converter of SharpDevelop?

June 18, 2011 10:41 AM
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.