API for C# code generation
Thesis title in Czech: | Rozhraní pro generování C# kódu |
---|---|
Thesis title in English: | API for C# code generation |
Key words: | generování kódu, C#, ILSpy, Coberec |
English key words: | code generation, C#, ILSpy, Coberec |
Academic year of topic announcement: | 2019/2020 |
Thesis type: | Bachelor's thesis |
Thesis language: | angličtina |
Department: | Department of Applied Mathematics (32-KAM) |
Supervisor: | doc. Mgr. Jan Hubička, Ph.D. |
Author: | hidden![]() |
Date of registration: | 24.02.2020 |
Date of assignment: | 26.02.2020 |
Confirmed by Study dept. on: | 16.03.2020 |
Date and time of defence: | 14.09.2020 09:00 |
Date of electronic submission: | 17.07.2020 |
Date of submission of printed version: | 31.07.2020 |
Date of proceeded defence: | 14.09.2020 |
Opponents: | Mgr. Filip Kliber |
Guidelines |
The goal of this project is to design and implement a library for
writing code generators. Its API will provide a semantic way to describe the result code, similar to System.Linq.Expressions from the .NET Framework. Unlike in System.Linq.Expressions, it will not rely on System.Reflection to provide the metadata (methods, types and other symbols) but will have its own API for declaring and using symbols from the C#/.NET typesystem. The API should help the programmer in following ways (compared to string concatenation and other syntax-only methods): * Early error checks - type, mutability inconsistencies should be reported as soon as possible, certainly before the code is emitted and the user tries to compile it. This should make it much easier to test the code generator. * Handling of edge cases that parametrized code generation easily run into - naming symbols, implicit conversion, choosing right method overrides. These should be handled without polluting the generated code with too much explicitness (global:: prefix everywhere, and so on) * Composability - the API will be expression-based, which allows the programmer to write generic helpers without worrying if the parameter will be an expression or a statement. * It should be also possible to write a function that processes the expression. It may, for example, remove dead code or lower an extension node into standard expressions. Implementation of the library will be based on a fork of the ILSpy decompiler since it had to handle many of the same edge cases when generating code. Part of the project will be a non-trivial code generator based on this library. It will translate GraphQL schema (types, scalars, and unions) into immutable C# classes. Note that this is just a reimplementation of an existing project on top of the new API. |
References |
* System.Linq.Expression:
https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions?view=netframework-4.7.2 * ILSpy project: https://github.com/icsharpcode/ILSpy/ * GraphQL Schema: https://graphql.org/learn/schema/ |