Extending the Mono C# compiler: is there any documentation or precedent?

前提是你 提交于 2019-12-03 23:32:57

Unfortunately, I cannot adequately answer your question, but if you look at the examples of C# extensions on Miguel de Icaza's blog, you will notice that all of them take the form of patches to the compiler, not plugins or extensions. This seems to indicate that there is no such API.

Note that all of these examples are of much smaller scope than what you seem to be working on:

These are mostly localized syntactic sugar, with no "interesting" behavior. The fourth patch, for example, implements Cω's syntactic sugar for IEnumerables, but without any of Cω's semantics that make this syntax interesting. If you look at the patch you can see that it literally does stupid syntactical expansion of ~TIEnumerable<T>, as opposed to Cω, where member access and method invocation are properly lifted over streams.

Microsoft Research's Phoenix Compiler Pipeline was once explicitly touted as the solution to such extensibility problems, but it seems that it now focuses mostly on optimizations and analysis on the IR level in a code generation backend. In fact, I'm not even sure if the project is even still alive.

Stefan Savev

The mono C# compiler is a bit of a hack. I spent around a week figuring out how to use information from the parse tree. The compiler does not produce any intermediate representation and code generation may break parts of the parse tree. Still, the parser and tokenizer might prove useful to you and you just take it from there. SharpDevelop also provides a C# parser. The SharpDevelop parser is easier to use than the mono C# parser. If F# also works for you, I would recommended. The source much cleaner than mono and available under open source license.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!