1 module bamboo.codegen.classes;
2 
3 import bamboo.codegen;
4 
5 string generateClass(ClassDeclaration cls, string baseType, bool generateStubs)
6 {
7     string format;
8     string firstFieldId = "0";
9     if (cls.fields)
10     {
11         firstFieldId = cls.fields[0].id.to!string;
12     }
13     format ~= "@TypeId(" ~ cls.id.to!string ~ ", `" ~ cls.symbol ~ "`, " ~ firstFieldId ~ ") ";
14 
15     if (!generateStubs)
16     {
17         format ~= "abstract ";
18     }
19 
20     format ~= "class ";
21     format ~= cls.symbol;
22 
23     if (cls.hasSuperclass)
24     {
25         format ~= " : ";
26         format ~= cls.parents[0].symbol;
27     }
28     else if (baseType.length > 0 && cls.symbol != baseType)
29     {
30         format ~= " : ";
31         format ~= baseType;
32     }
33 
34     format ~= "{";
35 
36     if (cls.hasConstructor)
37     {
38         assert(0, "Constructors are not supported.");
39     }
40 
41     format ~= "mixin ParentConstructors; ";
42 
43     foreach (field; cls.fields)
44     {
45         format ~= generateField(field, generateStubs);
46     }
47 
48     format ~= "}";
49     return format;
50 }
51 
52 string generateStruct(StructDeclaration strct)
53 {
54     string format;
55     format ~= "@TypeId(" ~ strct.id.to!string ~ ", `" ~ strct.symbol ~ "`, "
56         ~ strct.parameters[0].id.to!string ~ ")";
57     format ~= "struct ";
58     format ~= strct.symbol;
59     format ~= " {";
60     foreach (field; strct.parameters)
61     {
62         format ~= generateParameterField(field, true);
63     }
64     format ~= "}";
65     return format;
66 }