SlideShare a Scribd company logo
Project Roslyn: Exposing the C# and VB compiler’s code analysis
Project Roslyn: Exposing the C# and VB compiler’s code analysis
?   (formerly known as compiler-as-a-service)
Demo
Edit and
                                       IL Emitter




   Continue
                                        Emit API




Go To Definition
Extract Method
Signature Help
                                    Binding and Flow
                                      Analysis APIs
                                         Binder




  Quick Info
    Rename
   Find All
  References
Completion List
                                  Symbol API
                                                 Metadata
                                   Symbols


                                                  Import
Object Browser
  Navigate To
                                       Syntax Tree API
   Outlining
                                           Parser
   Colorizer
   Formatter
                   Compiler API
  Language




                                   Compiler
                                   Pipeline
   Service
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
Complete




Efficient
class C                                               CompilationUnit
{
    void M()
    {                                                 TypeDeclaration
    }
}// C
                                                     MethodDeclaration



                                              ParameterList        Block




var tree = SyntaxTree.ParseCompilationUnit("...");
class C                            CompilationUnit
{
    void M()
    {                      TypeDeclaration         EOF
    }
}// C
               class   C     {       MethodDeclaration       }



                            void      M      ParameterList           Block



                                               (         )       {           }
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
class C                            CompilationUnit
{
    void M()
    {                      TypeDeclaration         EOF
    }
}// C
               class   C     {       MethodDeclaration       }



                            void      M      ParameterList           Block



                                               (         )       {           }
class C                                              CompilationUnit
 {
     void M(int x)
     {                                        TypeDeclaration       EOF
     }
 }// C
                             class     C        {        MethodDeclaration       }



                                               void       M      ParameterList           Block


var 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);
class C                                                           CompilationUnit
  {
      void M(int x)
      {                                                      TypeDeclaration         EOF
      }
  }// C
                                       class        C          {       MethodDeclaration             }



                                                             void      M        ParameterList                    Block



                                                                         (           Parameter           )   {           }



var oldList = method.ParameterList;                                     PredefinedType           x
var newList = oldList.Update(
     openParenToken: oldList.OpenParenToken,
     parameters: Syntax.ParseParameterList("(int x)").Parameters,
     closeParenToken: oldList.CloseParenToken);                                int
var newRoot = tree.Root.ReplaceNode(oldList, newList);
class C                                                           CompilationUnit
  {
      void M(int x)
      {                                                      TypeDeclaration         EOF
      }
  }// C
                                       class        C          {       MethodDeclaration             }



                                                             void      M        ParameterList                    Block



                                                                         (           Parameter           )   {           }



var oldList = method.ParameterList;                                     PredefinedType           x
var newList = oldList.Update(
     openParenToken: oldList.OpenParenToken,
     parameters: Syntax.ParseParameterList("(int x)").Parameters,
     closeParenToken: oldList.CloseParenToken);                                int
var newRoot = tree.Root.ReplaceNode(oldList, newList);
Syntax
   Trees
             Compilation
             •   Symbols
             •   Semantic Model
             •   Flow Analysis
             •   Diagnostics
             •   Emit
References
Demo
Host Environment

      Events (e.g. key presses)
                                                    Apply
                          Workspace


                                         Edit               Edit
                            Solution            Solution2          Solutionn


Compilation          Project      Project


         Document          Document


         SyntaxTree
Demo
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
Demo
Dev Center: http://msdn.microsoft.com/nl-be/roslyn
Forum: http://social.msdn.microsoft.com/forums/nl-be/roslyn

Email: alexturn@microsoft.com
Project Roslyn: Exposing the C# and VB compiler’s code analysis
Project Roslyn: Exposing the C# and VB compiler’s code analysis

More Related Content

PDF
TWINS: OOP and FP - Warburton
ODP
OpenGurukul : Language : C++ Programming
PDF
C# / Java Language Comparison
PDF
The Ring programming language version 1.5.4 book - Part 82 of 185
PDF
C# for beginners
PDF
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
PDF
Writing beautiful code with Java 8
PPTX
TWINS: OOP and FP - Warburton
OpenGurukul : Language : C++ Programming
C# / Java Language Comparison
The Ring programming language version 1.5.4 book - Part 82 of 185
C# for beginners
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
Writing beautiful code with Java 8

What's hot (20)

PDF
Reflection in Go
PDF
김재석, C++ 프로그래머를 위한 C#, NDC2011
PPTX
from java to c
ODP
(2) c sharp introduction_basics_part_i
PDF
C++ idioms by example (Nov 2008)
PDF
Pythia Reloaded: An Intelligent Unit Testing-Based Code Grader for Education
PPTX
Whats New In C# 4 0 - NetPonto
PPTX
Unit testing concurrent code
PPTX
Java generics final
PDF
Virtual Functions
PDF
C# for-java-developers
PDF
Cpp reference card
PPTX
C# 6.0 Preview
PPT
Paradigmas de Linguagens de Programacao - Aula #4
PDF
JVM code reading -- C2
PDF
Why Java Sucks and C# Rocks (Final)
PDF
Back to the Future with TypeScript
PPT
Effective Java - Generics
ODP
Groovy Ast Transformations (greach)
PDF
Virtual Separation of Concerns
Reflection in Go
김재석, C++ 프로그래머를 위한 C#, NDC2011
from java to c
(2) c sharp introduction_basics_part_i
C++ idioms by example (Nov 2008)
Pythia Reloaded: An Intelligent Unit Testing-Based Code Grader for Education
Whats New In C# 4 0 - NetPonto
Unit testing concurrent code
Java generics final
Virtual Functions
C# for-java-developers
Cpp reference card
C# 6.0 Preview
Paradigmas de Linguagens de Programacao - Aula #4
JVM code reading -- C2
Why Java Sucks and C# Rocks (Final)
Back to the Future with TypeScript
Effective Java - Generics
Groovy Ast Transformations (greach)
Virtual Separation of Concerns
Ad

Viewers also liked (8)

PPTX
Roslyn API : SyntaxTree vs CodeDom, SemanticModel vs Reflection
PPT
D1 Overview of C# programming
PPT
Dependency parsing (2013)
PPT
Deep Parsing (2012)
PPT
Visula C# Programming Lecture 2
PPTX
SAS University Edition - Getting Started
PPT
C# basics
PPTX
C# Tutorial
Roslyn API : SyntaxTree vs CodeDom, SemanticModel vs Reflection
D1 Overview of C# programming
Dependency parsing (2013)
Deep Parsing (2012)
Visula C# Programming Lecture 2
SAS University Edition - Getting Started
C# basics
C# Tutorial
Ad

Similar to Project Roslyn: Exposing the C# and VB compiler’s code analysis (20)

PDF
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
PDF
Cartão de Referencia Padronizado Liguagem C
PDF
C ref card
PDF
C reference card
PDF
DEVCON1 - BooJs
PDF
C Reference Card (Ansi) 2
PDF
C++ Quick Reference Sheet from Hoomanb.com
PDF
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
PDF
C# Basics Quick Reference Sheet
PDF
Virtual machine and javascript engine
PDF
Decaf language specification
PDF
Declarative Name Binding and Scope Rules
PDF
What is new and cool j2se & java
PDF
Smalltalk implementation of EXIL, a Component-based Programming Language
PPTX
PPT
Comp102 lec 7
PPTX
DOC
Chapter 1 1
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Cartão de Referencia Padronizado Liguagem C
C ref card
C reference card
DEVCON1 - BooJs
C Reference Card (Ansi) 2
C++ Quick Reference Sheet from Hoomanb.com
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
C# Basics Quick Reference Sheet
Virtual machine and javascript engine
Decaf language specification
Declarative Name Binding and Scope Rules
What is new and cool j2se & java
Smalltalk implementation of EXIL, a Component-based Programming Language
Comp102 lec 7
Chapter 1 1

More from Microsoft Developer Network (MSDN) - Belgium and Luxembourg (20)

PPTX
Code in the Cloud - Ghent - 20 February 2015
PPTX
Executive Summit for ISV & Application builders - January 2015
PDF
Executive Summit for ISV & Application builders - Internet of Things
PPTX
Executive Summit for ISV & Application builders - January 2015
PPTX
PPTX
cloud value for application development
PPTX
PPTX
Inside the Microsoft TechDays Belgium Apps
PPTX
PPTX
PPTX
Applied MVVM in Windows 8 apps: not your typical MVVM session!
PPTX
Building SPA’s (Single Page App) with Backbone.js
PPTX
Deep Dive and Best Practices for Windows Azure Storage Services
PPTX
Building data centric applications for web, desktop and mobile with Entity Fr...
Code in the Cloud - Ghent - 20 February 2015
Executive Summit for ISV & Application builders - January 2015
Executive Summit for ISV & Application builders - Internet of Things
Executive Summit for ISV & Application builders - January 2015
cloud value for application development
Inside the Microsoft TechDays Belgium Apps
Applied MVVM in Windows 8 apps: not your typical MVVM session!
Building SPA’s (Single Page App) with Backbone.js
Deep Dive and Best Practices for Windows Azure Storage Services
Building data centric applications for web, desktop and mobile with Entity Fr...

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
A comparative analysis of optical character recognition models for extracting...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25-Week II
Mobile App Security Testing_ A Comprehensive Guide.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Machine Learning_overview_presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf

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

  • 3. ? (formerly known as compiler-as-a-service)
  • 5. Edit and IL Emitter Continue Emit API Go To Definition Extract Method Signature Help Binding and Flow Analysis APIs Binder Quick Info Rename Find All References Completion List Symbol API Metadata Symbols Import Object Browser Navigate To Syntax Tree API Outlining Parser Colorizer Formatter Compiler API Language Compiler Pipeline Service
  • 6. 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
  • 8. class C CompilationUnit { void M() { TypeDeclaration } }// C MethodDeclaration ParameterList Block var tree = SyntaxTree.ParseCompilationUnit("...");
  • 9. class C CompilationUnit { void M() { TypeDeclaration EOF } }// C class C { MethodDeclaration } void M ParameterList Block ( ) { }
  • 10. 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
  • 11. class C CompilationUnit { void M() { TypeDeclaration EOF } }// C class C { MethodDeclaration } void M ParameterList Block ( ) { }
  • 12. class C CompilationUnit { void M(int x) { TypeDeclaration EOF } }// C class C { MethodDeclaration } void M ParameterList Block var 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);
  • 13. class C CompilationUnit { void M(int x) { TypeDeclaration EOF } }// C class C { MethodDeclaration } void M ParameterList Block ( Parameter ) { } var oldList = method.ParameterList; PredefinedType x var newList = oldList.Update( openParenToken: oldList.OpenParenToken, parameters: Syntax.ParseParameterList("(int x)").Parameters, closeParenToken: oldList.CloseParenToken); int var newRoot = tree.Root.ReplaceNode(oldList, newList);
  • 14. class C CompilationUnit { void M(int x) { TypeDeclaration EOF } }// C class C { MethodDeclaration } void M ParameterList Block ( Parameter ) { } var oldList = method.ParameterList; PredefinedType x var newList = oldList.Update( openParenToken: oldList.OpenParenToken, parameters: Syntax.ParseParameterList("(int x)").Parameters, closeParenToken: oldList.CloseParenToken); int var newRoot = tree.Root.ReplaceNode(oldList, newList);
  • 15. Syntax Trees Compilation • Symbols • Semantic Model • Flow Analysis • Diagnostics • Emit References
  • 16. Demo
  • 17. Host Environment Events (e.g. key presses) Apply Workspace Edit Edit Solution Solution2 Solutionn Compilation Project Project Document Document SyntaxTree
  • 18. Demo
  • 19. 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
  • 20. Demo
  • 21. Dev Center: http://msdn.microsoft.com/nl-be/roslyn Forum: http://social.msdn.microsoft.com/forums/nl-be/roslyn Email: alexturn@microsoft.com