-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathStructDef.cs
48 lines (39 loc) · 1.11 KB
/
StructDef.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
namespace Generator.Types
{
public class StructDef : TypeDef
{
public override TypeKind Kind
{
get
{
return TypeKind.Struct;
}
}
public override bool CanBeSkipped
{
get
{
return !Type.Fields.Any();
}
}
private List<string> fields;
public StructDef(TypeDefinition t) : base(t) { }
public override void CollectDependencies()
{
fields = Type.Fields.Select(f => NameHelpers.PreventKeywords(f.Name) + ": " + TypeHelpers.GetTypeName(Generator, this, f.FieldType, TypeUsage.Raw)).ToList();
}
public override void Emit()
{
string fullname = '"' + Type.FullName + '"';
// TODO: derive(Eq) whenever possible?
Module.Append($@"
RT_STRUCT! {{ struct { DefinitionName } [{ fullname }] {{
{ string.Join(", ", fields) }{ (fields.Any() ? "," : "") }
}}}}");
}
}
}