A good IDE provides useful refactoring support. Since we’re planning to build a really good IDE for C, we have started adding a couple of them. Here is the list that is currently supported:
- Extract Into new Module: one or more module contents (functions, variables, statemachines, etc) can be selected and moved into a new module. The system prompts for the new module’s name, creates it, moves the contents there and then adds an import of the new module to the original module. The contents in the new module are set to be exported if they are referenced from the original one.
- Move to Imported Module: similar to the previous one, but this one does not create a new module. Instead it moves the selected contents into one of the modules that are already imported.
- Introduce Variable: an expression, maybe a sub-expression of another one, is selected. The refactoring then prompts for a name, and proceeds to create a local variable with that name. The type of the variable is the type of the selected expression and the init value is the expression itself. The occurrence of the expression is replaced by a reference to the new variable.
This is obviously a small list, but it was only three hours work. MPS provides a DSL/API for expressing refactorings, and it is relatively straight forward to implement those. MPS also provides support for data flow analysis. That’s a topic we’ll have to investigate soon, so we can build more sophisticated refactorings.