Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

The Microsoft Compiler Platform (Roslyn). A quick overview.

1.183 visualizaciones

Publicado el

What is the Microsoft Compiler Platform, why was it created and who might find it useful.
This talk will contain an overview of the following features together with loads of code samples.

New C# 6 language features.
Compiler API, working with syntax, semantics, symbols, dataflow and control flow.
Diagnostics and code fixes.
Analyzers and NuGet.
Scripting and REPL.

https://github.com/Djohnnie/Roslyn4Visug

Publicado en: Tecnología

The Microsoft Compiler Platform (Roslyn). A quick overview.

  1. 1. The Microsoft Compiler Platform Johnny Hooyberghs johnny.hooyberghs@involved-it.be @djohnnieke
  2. 2. New events in the coming months • May: no event • June • Dennis Doomen (Netherlands) • Session TBA • September • Christos Matskas (UK) • Session TBA • October • You?
  3. 3. Thanks for partnering with Visug!
  4. 4. The Microsoft Compiler Platform Johnny Hooyberghs johnny.hooyberghs@involved-it.be @djohnnieke
  5. 5. I work for Involved-IT A group of passionate software engineers who design, build and deliver software using .NET and the best bits of the Web “ ”
  6. 6. agenda • Roslyn Overview • New C# 6 language features • Compiler API • syntax, compilation, symbols, data flow, control flow • Diagnostics and code fixes • Analyzers and NuGet • Scripting
  7. 7. The .NET Compiler Platform ("Roslyn") provides open-source C# and Visual Basic compilers with rich code analysis APIs It enables building code analysis tools with the same APIs that are used by Visual Studio
  8. 8. roslyn overview • Rewrite of the VB and C# compilers • Written in C# and VB itself • Language services integrated in IDE • Intellisense • Code browsing experiences • Refactorings • ... • Code analysis from managed languages • Build compilers and tools
  9. 9. why roslyn • Managed languages • Better productivity • New language features are easier to implement • 1 compiler, different contexts • csc.exe, vbc.exe • Background compilers in IDE • Snippet compiler • Support for experimentation and prototyping • Richer tooling, 3rd party extensions, education
  10. 10. current compiler compiler C# VB IL
  11. 11. current compiler parser symbols binder IL emitter C# VB IL
  12. 12. roslyn compiler C# VB IL Syntax Tree API Symbol API Binding & Flow Analysis API Emit API
  13. 13. By rewriting the C# and VB compiler it becomes easier to implement new language features Smaller language features are finally worked on because of the smaller impact
  14. 14. C# history C# 1 Managed C# 2 Generics C# 3 LINQ C# 4 Dynamic programing C# 5 Asynchronous programing C# 6 Compilel Platform “Roslyn”
  15. 15. new C# 6 language features • Using static • Nameof operator • Property initializers • Constructor assignment to getter-only properties • Expression bodies • String interpolation • Null conditional • Index initializer • Exception filters • Await in catch/finally
  16. 16. compiler API – syntax • Textual representation of source code • Represented as a tree data structure • Built from a sequence of tokens Console . WriteLine ( x ) ; identifier dot open paren close paren semicolonidentifier identifier
  17. 17. compiler API – tokens • Identifiers • Console, Math, WriteLine, System, x, ... • Keywords • if, static, class, return, ... • Operators • +, *, &&, %, ... • Punctuation • ., ;, ... • Trivia • whitespace, comments
  18. 18. compiler API – constructs • Declarations • Types, Members • Statements • if( ... ) • Clauses • else( ... ), where flag • Expressions • Invocations or expressions using operators
  19. 19. compiler API – trees Console . WriteLine ( x ) ; identifier dot open paren close paren semicolonidentifier identifier WS CRLF trivia trivia SimpleMemberAccessExpression IdentifierName IdentifierName InvocationExpression ExpressionStatement ArgumentList Argument IdentifierName
  20. 20. compiler API – compilation • Code compilation as a service • Based upon • Syntax tree • Compilation options • Metadata references • Use Emit to write to a file • Compilation results including diagnostics • Semantic analysis
  21. 21. compiler API – symbols • GetSemanticModel on a compilation • Get symbol information • Get speculative symbol information • Find the closest enclosing symbol from a position • Check if symbols are accessible from a position • Lookup symbols from a position • Getting constant values for literals
  22. 22. compiler API – flow analysis • Data flow analysis • How does data flow into and out of a region • Useful for Extract Method analysis • Control flow analysis • How does control get transferred in and out of a region • Reachability • Entry points • Exit point • Return statements
  23. 23. diagnostics and code fixes • Stylistic advice for source code • Like StyleCop rules • Implement your own rules • Supported in Visual Studio 2015 • Provide solutions to rule violations • Ligth bulb experience • Provides preview for code fixes
  24. 24. analyzers and NuGet • Creating a VSIX extension for Visual Studio to distribute analyzers • Create a NuGet package to install analyzers inside your projects • Distribute analyzers with your NuGet packages, for example to accommodate your frameworks and API’s
  25. 25. scripting • Evaluate C# or VB expressions • Getting variables from scripts • Adding references and using namespaces • Dynamic support for scripts • Setting globals to pass data into a script • Creating a delegate from a script • REPL (read-eval-print-loop)
  26. 26. and we’re done Johnny Hooyberghs johnny.hooyberghs@involved-it.be @djohnnieke

×