private void VisitTypeDeclaration(TypeDeclarationSyntax node)
{
tcb = new TypeCodeBuilder();
tcb.Top.AppendIndent();
if (node.TypeParameterList != null &&
node.TypeParameterList.Parameters.Count > 0)
{
tcb.Top.Append("template <");
var ps = node.TypeParameterList.Parameters;
for (int i = 0; i < ps.Count; ++i)
{
var p = ps[i];
tcb.Top.Append("typename ").Append(p.Identifier.ToString());
if (i + 1 != ps.Count)
tcb.Top.Append(", ");
}
tcb.Top.Append("> ");
}
tcb.Top.Append("class " + node.Identifier);
// here comes the tricky part: base class declarations
if (node.BaseList != null)
{
var types = node.BaseList.Types;
for (int i = 0; i < types.Count; ++i)
{
var t = types[i];
if (i == 0) tcb.Top.Append(" : ");
tcb.Top.Append("public ").Append(t.Type.ToString());
if (i + 1 != types.Count)
tcb.Top.Append(", ");
}
}
tcb.Top.AppendLine(" { ");
if (node is ClassDeclarationSyntax)
{
var cds = (ClassDeclarationSyntax)node;
base.VisitClassDeclaration(cds);
if (cds.HasInitializableMembers(model) && !cds.HasDefaultConstructor())
{
tcb.Public.AppendLineWithIndent(cds.Identifier + "();");
}
}
else if (node is InterfaceDeclarationSyntax)
{
var ids = (InterfaceDeclarationSyntax)node;
base.VisitInterfaceDeclaration(ids);
}
tcb.Bottom.AppendLineWithIndent("};");
// flush tcb to cb
cb.Append(tcb.ToString());
}