Project Roslyn: Exposing the C# and VB compiler’s code analysis

1,785 views

Published on

More info on http://www.techdays.be

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,785
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
40
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Project Roslyn: Exposing the C# and VB compiler’s code analysis

  1. 1. ? (formerly known as compiler-as-a-service)
  2. 2. Demo
  3. 3. Edit and IL Emitter Continue Emit APIGo To DefinitionExtract MethodSignature Help Binding and Flow Analysis APIs Binder Quick Info Rename Find All ReferencesCompletion List Symbol API Metadata Symbols ImportObject Browser Navigate To Syntax Tree API Outlining Parser Colorizer Formatter Compiler API Language Compiler Pipeline Service
  4. 4. Editor Services Code Actions Classification Completion Outlining … Code Formatting Find All References Name Simplification … Services Workspace API Syntax Tree Symbol Binding and Flow Scripting Compiler API API Analysis APIs Emit API API
  5. 5. CompleteEfficient
  6. 6. class C CompilationUnit{ void M() { TypeDeclaration }}// C MethodDeclaration ParameterList Blockvar tree = SyntaxTree.ParseCompilationUnit("...");
  7. 7. class C CompilationUnit{ void M() { TypeDeclaration EOF }}// C class C { MethodDeclaration } void M ParameterList Block ( ) { }
  8. 8. class∙C CompilationUnit{∙∙∙∙void∙M()∙∙∙∙{ TypeDeclaration EOF∙∙∙∙}}// C class SP C EOL { EOL MethodDeclaration } // C EOL SPx4 void SP M ParameterList Block ( ) EOL SPx4 { EOL SPx4 } EOL
  9. 9. class C CompilationUnit{ void M() { TypeDeclaration EOF }}// C class C { MethodDeclaration } void M ParameterList Block ( ) { }
  10. 10. class C CompilationUnit { void M(int x) { TypeDeclaration EOF } }// C class C { MethodDeclaration } void M ParameterList Blockvar oldList = method.ParameterList;var newList = oldList.Update( ( ) { } openParenToken: oldList.OpenParenToken, parameters: Syntax.SeparatedList(var oldList = method.ParameterList; Syntax.Parameter(var newList = oldList.Update( typeOpt: Syntax.ParseTypeName("int "), openParenToken: oldList.OpenParenToken, identifier: Syntax.Identifier("x"))), parameters: Syntax.ParseParameterList("(int x)").Parameters, closeParenToken: oldList.CloseParenToken);var newRoot = tree.Root.ReplaceNode(oldList, newList);
  11. 11. class C CompilationUnit { void M(int x) { TypeDeclaration EOF } }// C class C { MethodDeclaration } void M ParameterList Block ( Parameter ) { }var oldList = method.ParameterList; PredefinedType xvar newList = oldList.Update( openParenToken: oldList.OpenParenToken, parameters: Syntax.ParseParameterList("(int x)").Parameters, closeParenToken: oldList.CloseParenToken); intvar newRoot = tree.Root.ReplaceNode(oldList, newList);
  12. 12. class C CompilationUnit { void M(int x) { TypeDeclaration EOF } }// C class C { MethodDeclaration } void M ParameterList Block ( Parameter ) { }var oldList = method.ParameterList; PredefinedType xvar newList = oldList.Update( openParenToken: oldList.OpenParenToken, parameters: Syntax.ParseParameterList("(int x)").Parameters, closeParenToken: oldList.CloseParenToken); intvar newRoot = tree.Root.ReplaceNode(oldList, newList);
  13. 13. Syntax Trees Compilation • Symbols • Semantic Model • Flow Analysis • Diagnostics • EmitReferences
  14. 14. Demo
  15. 15. Host Environment Events (e.g. key presses) Apply Workspace Edit Edit Solution Solution2 SolutionnCompilation Project Project Document Document SyntaxTree
  16. 16. Demo
  17. 17. Code Action A representation of a code change• Produces both an edit and a preview of that edit Code Issue An interesting span of source code• Called for every node, token or trivia in a source file• Optional: May be squiggled in the editor and shown in the Error List• Optional: May provide one or more Code Actions Code Refactoring A contextually-available Code Action• Operates on the current selection in the editor• Must provide one or more Code Actions
  18. 18. Demo
  19. 19. Dev Center: http://msdn.microsoft.com/nl-be/roslynForum: http://social.msdn.microsoft.com/forums/nl-be/roslynEmail: alexturn@microsoft.com

×