MLLIF
a MLIR-based Language to Language Interoperability Flyover
Loading...
Searching...
No Matches
TypeDeclWriter.cs
Go to the documentation of this file.
1using Microsoft.CodeAnalysis;
3
5
6public readonly struct TypeDeclWriter(INamedTypeSymbol symbol) : ICodeWriter
7{
8 public IEnumerable<WorkspaceDiagnostic> WriteTo(CodeWriter w, CodeContext ctx)
9 {
10 if (!symbol.IsTarget())
11 yield break;
12
13 w.WriteLine(
14 $$"""
15 class [[mllif::export]] {{symbol.Name}} {
16 void* _handle;
17 {{symbol.Name}}(void* handle) : _handle(handle) {}
18 public:
19 {{symbol.Name}}({{symbol.Name}} const&) = delete;
20 {{symbol.Name}}& operator=({{symbol.Name}} const&) = delete;
21 """);
22 w.Indent++;
23
24 if (!symbol.IsStatic)
25 {
26 w.WriteLine($"~{symbol.Name}();");
27 }
28
29 ctx.Add(symbol);
30 foreach (var method in symbol
31 .GetMembers()
32 .OfType<IMethodSymbol>()
33 .Where(SymbolExtension.IsTarget))
34 foreach (var diag in new MethodDeclWriter(method).WriteTo(w, ctx))
35 yield return diag;
36
37 w.Indent--;
38 w.WriteLine("};");
39 }
40}