ITypeReference from Ast.NamespaceClassDeclaration

Jan 22, 2010 at 4:55 AM
Edited Jan 22, 2010 at 5:04 AM

Hello. I'm back to my compiler.

 

If I'm compiling something like (C#-like notation)

 

new Alpha()

 

where Alpha is a class defined in the assembly that I'm compiling, all I can have is a (possibly incomplete) NamespaceClassDeclaration of Alpha.

In order to create a CreateObjectInstance I need a TypeExpression and the only way to make a TypeExpression is MicrosoftCci.Ast.TypeExpression.For(ITypeReference).

How do I get a ITypeReference from a NamespaceClassDeclaration?

Is there another way to create a TypeExpression?

In my older compiler prototype, where I was only using CCI Metadata but not CCI Ast, I would create a Microsoft.Cci.MutableCodeModel.NamespaceTypeDefinition instead of NamespaceClassDeclaration. Obviously I was able to use the NamespaceTypeDefinition itself as a ITypeReference.

I don't understand what's the CCI Ast way to do the same thing.

Thanks!

Coordinator
Jan 22, 2010 at 5:34 AM

You need to use a NamedTypeExpression. Also have a look at the other subclasses of TypeExpression.

And, of course, specsharp.codeplex.com contains a budding compiler for Spec# using CCI2 (this CCI), hiding away in the SpecSharp2 subdirectory. If you trace through how the Spec# compiler compiles a program from source to IL, you can get quick answers to many questions. ;-)

Jan 22, 2010 at 7:20 PM

Thanks for the help.

Yes, I had a look to Spec# but I got a bit scared. I didn't know about the new version. I'll have a look at it.

Thanks again.

Jan 27, 2010 at 6:19 AM

Yes, I found the SpecSharp2 compiler.

I think that last time I checked that compiler I overlooked v2. I thought that the compiler performed a shell-out to another compiler. Maybe I misunderstood or got lost in the sources.

The SpecSharp2 compiler is a great source of information.