This project is a SrcML Transform project that relies on the ABB Visual Studio Program Transformation tool. This code was used in a tool demonstration given at FSE 2012. The slides are available here.
We want to demonstrate a fairly wide-ranging code transformation on a real piece of software. In this demo, we want to ensure that all uses of the new
operator are wrapped in a try
/catch
block in order to check for errors. This was a compiler change seen in Visual Studio 2005:
By default, any call to new that fails will throw an exception.
Microsoft provided other ways adapt to this change, but for our purposes, we will assume that the best change is to modify the source code in order to reflect the C++ standard.
In order to run this code, there are a few setup steps.
First, download SrcML.NET and install the program transformation Visual Studio add-in (see the README for details).
Second, download the code for Notepad++ and extract it somewhere on disk. I used version 6.2 in the demonstration, but the transformations should work on other versions as well.
The demonstration is fairly straightforward.
- Launch Visual Studio
- Open the "NPPTransformExample" project
- Enable the "Program Transformation" addin from the add-ins menu. The "transformation preview pane" should appear.
- Select the first "Browse..." button to select a source folder.
- Navigate to the downloaded copy of Notepad++
- Select the "PowerEditor" directory
- Press "OK"
- The buttons will disable briefly while the source code is converted into srcML.
- Build the project -- the add-in should update saying that three transformations have been loaded.
- You can now play with any of the provided transformations. There are three:
AllNewQuery
: This is used to demonstrate a basic query and to explore how thenew
operator is used in Notepad++. You can use the category view on the left to see what kinds of statementsnew
operators appear in.NewExpressionTransform
: This is used to transform all uses of thenew
operator that occur in expression statements.NewDeclarationTransform
: This is used to transform all uses of thenew
operator that occur in declaration statements.
In order to preview a transform, simply press "Test". You can double click on any of the results to see the original source code. Once you're happy with the results, select an output directory (the 2nd "Browse..." button) and then press "Execute." Notepad++ compiles, runs, and operates without error. This is exactly what we want for an adaptive maintenance change!