Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler as a service: How to build Refactoring tools?

Lisa Feigenbaum from Microsoft talks here about "Compiler as a service". I have read this would make it easier to build refactoring tools. How? Mono's CAAS is great but if Microsoft version is similar I don't see how this specific use case is done.

like image 951
Yaron Naveh Avatar asked May 16 '11 16:05

Yaron Naveh


2 Answers

The Roslyn CTP includes a walkthrough for building s "Code Action" which is our terminology for something that can be either "quick fix", if it is linked to something wrong with the code, or a refactoring if it is offered contextually.

Also take a look at the CodeRefactoring project template that you will see in Visual Studio if you install the Roslyn CTP.

like image 27
Kevin Pilch Avatar answered Sep 16 '22 22:09

Kevin Pilch


"Compiler as a service" means breaking down the compiler into individual pieces.

Instead of having one big monolithic black box where source code goes into one end and compiled assemblies comes out the other, you get lots of smaller (black) boxes with typed output.

So you could, for instance, feed the source code into one box, and get an abstract syntax tree (AST) out the other. This tree could then be manipulated, before it is fed into the optimizer, out of which comes some other representation of the code, which could be fed into the compiler, which then outputs executable code.

Since I don't know a lot about the exact plans for the "compiler as a service" part of a future .NET, the above is just a wild guess, but that's how I see the possibilities.

Refactoring could then operate on the AST, and I would assume there was a way to go from the AST back to the original source code, both through mapping and conversion (mapping means you could take a node in the AST and ask "which part of the source code does this node correspond to", and conversion would mean "could you please give me the source code that this AST now represents, after I have modified it".)

For instance, I would see both JetBrains and DevExpress, both making refactoring tools for Microsoft, having to evaluate their own efforts into writing code that reads and picks apart code for refactoring vs. using the one provided by the CAAS.

like image 83
Lasse V. Karlsen Avatar answered Sep 16 '22 22:09

Lasse V. Karlsen