private void GenerateStruct(Struct structNode)
{
TypeNode newStruct = Templates.GetTypeTemplateByName("Struct");
Method writer = (Method)Templates.GetMemberByName(newStruct.Members, "WriteString");
// Replace all references to the struct name
Replacer.Replace(newStruct, newStruct.Name, structNode.Name);
for (int i = 0, n = structNode.Members.Count; i < n; i++)
{
Field f = structNode.Members[i] as Field;
if (f != null)
{
// Clone the field since we might tinker with it (see other TODO below)
Field newField = (Field)f.Clone();
if (GetTypeClassification(f.Type) == TypeClassification.Heap)
newField.Type = this.ZingPtrType;
else if (!IsPredefinedType(f.Type))
newField.Type = new TypeExpression(new QualifiedIdentifier(
new Identifier("Application"), f.Type.Name), f.Type.SourceContext);
newStruct.Members.Add(newField);
newField.DeclaringType = newStruct;
writer.Body.Statements.Add(GetWriterStatement("this", f.Type, newField.Name));
}
}
// TODO: Add a CompareTo method to the struct (low priority)
string s = writer.FullName;
InstallType(newStruct);
}