The document discusses Roslyn, a .NET compiler platform that provides open-source C# and Visual Basic compilers with rich code analysis APIs. It outlines the compiler pipeline including parsing, binding, and IL emission, as well as APIs for syntax trees, symbols, and emitting. The document also describes how Roslyn enables language services like auto-completion, navigation, and refactoring tools.
5. compiler API
binding and
syntax tree API symbol API flow analysys emit API
API
6. edit and
continue
go to
definition
extract
method
signature
help
quick info
rename
language service
find all
references
completion
list
object
browser
navigate to
outlining
colorizer
formatter
7. API layers
compilers scripting
workspace services
8. working with syntax
Syntax tree: represent the lexical and syntactic structure of source code
o full fidelity
o round-trippable back
o Immutable
Syntax node: represent syntactic constructs (such as declarations, statements,
clauses and expression)
Syntax tokens: represent the smallest syntactic fragment of the code
Syntax trivia: represent the parts of the source text that are largely insignificant
for normal understanding of the code (such as whitespace, comments and
processor directives)
Spans
Kinds
Errors
9. working with semantic
Compilation: represent everything needed to compile C# or VB.Net program
(including all the assembly references, compiler options and source files)
Symbol: represents a distinct element declared by source code or imported from
an assembly as metadata
Semantic model: represents all the semantic information for a single source file
Editor's Notes
First the parse phase, where source is tokenized and parsed into syntax that follows the language grammar. Second the declaration phase, where declarations from source and imported metadata are analyzed to form named symbols. Next the bind phase, where identifiers in the code are matched to symbols. Finally, the emit phase, where all the information built up by the compiler is emitted as an assembly.
The parsing phase is exposed as a syntax tree, the declaration phase as a hierarchical symbol table, the binding phase as a model that exposes the result of the compiler’s semantic analysis and the emit phase as an API that produces IL byte codes.
The compiler layer contains the object models that correspond with information exposed at each phase of the compiler pipeline, both syntactic and semantic. The compiler layer also contains a representation of a single invocation of a compiler, including assembly references, compiler options, and source code files. There are two distinct, but similar in shape, APIs that represent the C# language and the Visual Basic language. This layer has no dependencies on Visual Studio components.The scripting layer represents a runtime execution context for C# or Visual Basic snippets of code. It contains a scripting engine that allows evaluation of expressions and statements as top-level constructs in programs. This layer has no dependencies on Visual Studio components.The workspace layer is the starting point for doing code analysis and refactoring over entire solutions. It assists you in organizing all the information about the projects in a solution into single object model, offering you direct access to the compiler layer object models without needing to parse files, configure options or manage project to project dependencies.This layer is commonly used when implementing code analysis and refactoring tools that function within a host environment like the Visual Studio IDE, however it has no dependencies on Visual Studio components.The services layer contains all the Visual Studio IDE features, such as IntelliSense, refactorings, and code formatting features. It also contains the Services APIs, which allow a user to easily extend Visual Studio. This layer has a dependency on the Visual Studio text editor and the Visual Studio software development kit (SDK).