API overview

The code model is defined in Microsoft.Cci.CodeModel.dll. It defines a collection of interfaces that provide read-only access to a tree-like object model that defines nodes for common types of statements and expressions. The goal of the API design is to provide a model that is familiar to programmers of languages such as C#, as well as being expressive enough to model everything that can be expressed in CLR IL.

The code model also includes concepts such as nested functions (C# anonymous delegates) that are present in many languages, but akward to express in IL. Since these are also akward for the code model to IL translator to deal with, the code model has a subset called the normalized code model and a "code model normalizer" that transforms full code models into normalized code models. Another set of transformation is provided by the AssertionAdder, which makes the implicit assertions in a code model (such as that a pointer which is deferenced is also not null) explicit, so that error checking tools need only concern themselves with explicit assertions.

Since the code model is accessed via read-only interfaces to objects that are required to appear immutable to clients using the interfaces, changes must be introduced by making a copy of the model. The mutable code model defined in Microsoft.Cci.MutableCodeModel provides a set of classes that are mutable, but that also implement the code model interfaces. Correct use of these classes requires the constructor to cease changing any objects reachable from a root, as soon as the root is given out via its immutable interface.

The AST model is defined in Microsoft.Cci.AstsProjectedAsCodeModel.dll. This library provides base classes that can be subclassed to provide AST nodes for use by compilers. The base classes emphasize extensibility and customizability and take care of things such as binding names to definitions, overload resolution and error checking. The base classes are also designed to support incremental compilation, while allowing for efficient projection onto the immutable code model. AST nodes are composable regardless of programming language, making it possible to use more than one language to construct a single file CLR assembly, namespace, type or even method.

Last edited Apr 9, 2009 at 6:38 PM by hermanv, version 2


No comments yet.