Projecting on CodeModel

Feb 17, 2010 at 4:21 PM
Edited Feb 17, 2010 at 4:29 PM

Sorry to ask again about this subject.

1) I have my specialized compilation part that provides a root namespace declaration

2) Almost all elements of my ast can be projected on CCI-AST classes and so I will just add the appropriate namespace member declarations

3) ONE of my ast elements can't be projected on CCI-AST classes.

Two questions:

1) since (as I mentioned in the last post) I need to start with a custom TypeDefinition, I attempted to do that and I ended up cut-and-pasting like 10 of your classes just to make something that apparently is not that different. Is it really this the way I'm supposed to work? If it is, "CCI code and AST" seems to be a bit locked. The strange thing is that wandering through your code, I find few places that could be used to implement what I want and they are not virtual or are virtual but internal.

2) supposing I found the definitive way to implement this my-ast-to-codemodel projection, how do I stick that into your Assembly class? how does it gets into the IL generation mechanism?

I hope I'm not abusing of your patience.

Coordinator
Feb 17, 2010 at 5:16 PM

1) It is somewhat difficult to anticipate all the ways in which a base class can be extended, so I'm not surprised that you are running into situations where the extension mechanism you need has not been provided. Since the sources are available to you, you can of course change the base classes to provide for your scenario. It will also be nice if you can make your changes available for possible inclusion in the shared source tree.

2) Once you've projected your AST onto the CodeModel (projecting onto the base AST classes is an indirect way of doing that), you can use PeWriter to write out the projection to an assembly on disk. A CodeModel method body already knows how to project itself onto IL, so that part should come for free.

Perhaps it would be worthwhile to demonstrate your problem by extending the SmallBasic sample. That way I can look at the problem in more detail and we also document the solution for the next person who runs into this problem.

 

Feb 21, 2010 at 6:22 PM

Thanks for your answer.

Currently I'm trying again to work against CCI-Metadata only.

My compiler is extensible in the sense that some of the assemblies referenced by a "project" can affect the compiler behaviour, providing more language costructs or performing some processing on the AST.

The problem I mentioned earlier is something I need to get working soon and it's implemented as simple example of this extensibility feature.

I'm still not sure that would work with CCI-AST in any productive way. I'm not sure it won't either. I don't have enough knowledge at the moment and I'm not even barely as good with programming languages as you are.

Unfortunately I can't focus only on the language part of my work. I need to hammer a little here and a little there, so to speak. So it's possible that I'm wrong and I will switch back to CCI-AST again.

I understand CCI a little better now anyway, so it's possible that in some time I realize how I can do that with CCI-AST or maybe that will only few changes/improvements to CCI-AST it could work in my case too.

Thanks again!