[Mono-devel-list] ICodeParser && Mono
Jonathan Pryor
jonpryor at vt.edu
Wed Feb 4 20:59:55 EST 2004
Below...
On Wed, 2004-02-04 at 13:21, Christian Birkl wrote:
> Hi all,
>
> Is there something equivalent to Microsoft.CSharp namespace in Mono? I
> can't find any in the current class/ directory in recent cvs. I'm
> specifically interested in Microsoft.CSharp.CSharpProvider. I'd like to
> do some code analysing stuff via ICodeProvider, which can create a
> CodeCompileUnit via .CreateParser().Parse(). This would be a much nicer
> way than doing the parsing on my own. But unfortuntly .CreateParser() is
> defined to *always* return null. It would be nice if Mono would break
> this MS behaviour (or somehow provide a second .CreateParser() method.).
Are you sure it's not CSharpCodeProvider? There's one in
<cvs root="mcs"/>/class/System/Microsoft.CSharp/CSharpCodeProvider.cs.
There's also a Microsoft.CSharp namespace in class/Cscompgd.
I don't know if Mono would be willing to break compatibility, but I
suspect not.
> My second question is wether mcs (mono c# compiler) internally actually
> uses System.CodeDom for its code creation or not. And if yes, how can i
> access the CodeDom created by the parser?
I believe this is a misunderstanding of what CodeDom is for. CodeDom
isn't for *parsing* code. It's for *generating* code. Not CIL code.
Source code.
CodeDom would be used by e.g. VisualStudio for generating templates: you
would describe, via CodeDom, that you want a class (MyClass), with a
method (Main), and some comments ("Do something here"). This CodeDom
description could then be used to generate the template code in VB.NET,
C#, JavaScript... Anything that has a CodeDom provider. It's to
generate *human readable* source code.
This was discussed -- in excruciating depth because of perceived GPL
"backdoor" -- in May 2002, when miguel noted:
The System.CodeDOM API is a mechanism to "build" source code
through an API. It is just an abstraction so that ASP.NET can
"create" pages built on a number of languages.
Once you have constructed your "CodeDOM", it is written into a
file, and an external compiler is invoked. So there are no
licensing problems.
See: http://lists.ximian.com/archives/public/mono-list/2002-May/005929.html
To generate IL, System.Reflection.Emit is used. This is what mcs does.
You can also use PEAPI (in mcs CVS), or just directly emit the opcodes
(if you're writing in a non-managed environment).
I think PEAPI can also be used to parse existing IL code, but I'm not
entirely sure.
- Jon
More information about the Mono-devel-list
mailing list