37
37
string[] codelines;
40
void printCode(const GProgram p, CodeStream s)
42
foreach(gstruct; p.structs)
43
printStruct(gstruct, s);
45
foreach(gfunction; p.functions)
46
printFunction(gfunction, s);
42
void printCode(const GProgram p, CodeStream s);
50
void printStruct(const GStruct gstruct, CodeStream s)
52
assert(gstruct.name != "");
53
s.writefln("struct %s", gstruct.name);
57
foreach(memberDesc; gstruct.members)
58
printMember(memberDesc, s);
65
void printFunction(const GFunction gfunction, CodeStream s)
67
const retType = firstNotEmpty(gfunction.retType, "void");
69
s.writefln("%s %s(%s)", retType, gfunction.name,
70
myJoin(gfunction.args, ", "));
74
if(gfunction.retType != "")
75
s.writefln("%s r;", gfunction.retType);
77
foreach(line; gfunction.codelines)
78
s.writefln("%s", line);
80
if(gfunction.retType != "")
81
s.writefln("return r;");
88
string firstNotEmpty(string a, string b)
96
string myJoin(const string[] tab, string sep)
100
foreach(i, element; tab)
111
void printMember(const GStructMember desc, CodeStream s)
114
line ~= format("%s %s", desc.type, desc.name);
116
if(desc.arrayLength > 1)
117
line ~= format("[%s]", desc.arrayLength);
121
if(desc.comment != "")
122
line ~= format("// %s", desc.comment);
124
s.writefln("%s", line);
45
void printStruct(const GStruct gstruct, CodeStream s);
46
void printFunction(const GFunction gfunction, CodeStream s);