2002-01-05 12:45:55 +00:00
|
|
|
// GtkSharp.Generation.StructGen.cs - The Structure Generatable.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class StructGen : StructBase, IGeneratable {
|
|
|
|
|
|
|
|
public StructGen (String ns, XmlElement elem) : base (ns, elem) {}
|
|
|
|
|
|
|
|
public String MarshalType {
|
|
|
|
get
|
|
|
|
{
|
2002-02-06 20:09:14 +00:00
|
|
|
return QualifiedName;
|
2002-01-05 12:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String CallByName (String var_name)
|
|
|
|
{
|
|
|
|
return var_name;
|
|
|
|
}
|
|
|
|
|
2002-02-08 23:56:27 +00:00
|
|
|
public String FromNative(String var)
|
|
|
|
{
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
public void Generate (SymbolTable table)
|
|
|
|
{
|
2002-03-24 17:04:25 +00:00
|
|
|
char sep = Path.DirectorySeparatorChar;
|
|
|
|
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
|
|
|
if (!Directory.Exists(dir)) {
|
|
|
|
Directory.CreateDirectory(dir);
|
2002-01-07 00:25:51 +00:00
|
|
|
}
|
2002-03-24 17:04:25 +00:00
|
|
|
String filename = dir + sep + Name + ".cs";
|
2002-01-05 12:45:55 +00:00
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
2002-01-05 12:45:55 +00:00
|
|
|
StreamWriter sw = new StreamWriter (stream);
|
|
|
|
|
|
|
|
sw.WriteLine ("// Generated File. Do not modify.");
|
|
|
|
sw.WriteLine ("// <c> 2001 Mike Kestner");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
sw.WriteLine ("namespace " + ns + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
sw.WriteLine ("\tusing System.Collections;");
|
|
|
|
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
|
|
|
|
sw.WriteLine ("\tpublic class " + Name + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
|
|
|
|
|
|
|
XmlElement member = (XmlElement) node;
|
|
|
|
|
|
|
|
switch (node.Name) {
|
|
|
|
case "field":
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.IgnoreCount++;
|
2002-01-06 13:33:25 +00:00
|
|
|
// GenField(member, table, sw);
|
2002-01-05 12:45:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "callback":
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.IgnoreCount++;
|
2002-01-05 12:45:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "constructor":
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.IgnoreCount++;
|
2002-01-05 12:45:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "method":
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.IgnoreCount++;
|
2002-01-05 12:45:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Console.WriteLine ("Unexpected node");
|
|
|
|
break;
|
2002-01-17 00:26:46 +00:00
|
|
|
}
|
2002-01-05 12:45:55 +00:00
|
|
|
}
|
2002-01-17 00:26:46 +00:00
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
sw.WriteLine ("\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("}");
|
|
|
|
|
|
|
|
sw.Flush();
|
|
|
|
sw.Close();
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.StructCount++;
|
2002-01-05 12:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|