2002-01-05 12:45:55 +00:00
|
|
|
// GtkSharp.Generation.EnumGen.cs - The Enumeration Generatable.
|
2002-01-04 02:02:28 +00:00
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
namespace GtkSharp.Generation {
|
2002-01-04 02:02:28 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class EnumGen : IGeneratable {
|
|
|
|
|
|
|
|
private String ns;
|
|
|
|
private XmlElement elem;
|
|
|
|
|
|
|
|
public EnumGen (String ns, XmlElement elem) {
|
|
|
|
|
|
|
|
this.ns = ns;
|
|
|
|
this.elem = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String Name {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return elem.GetAttribute("name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String CName {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return elem.GetAttribute("cname");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
public String QualifiedName {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return ns + "." + elem.GetAttribute("cname");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
public String MarshalType {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "int";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String CallByName (String var_name)
|
|
|
|
{
|
|
|
|
return "(int) " + var_name;
|
|
|
|
}
|
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
public void Generate (SymbolTable table)
|
2002-01-04 02:02:28 +00:00
|
|
|
{
|
2002-01-07 00:25:51 +00:00
|
|
|
if (!Directory.Exists("..\\" + ns.ToLower() + "\\generated")) {
|
|
|
|
Directory.CreateDirectory("..\\"+ns.ToLower()+"\\generated");
|
|
|
|
}
|
2002-01-04 02:02:28 +00:00
|
|
|
String filename = "..\\" + ns.ToLower() + "\\generated\\" + Name + ".cs";
|
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
2002-01-04 02:02:28 +00:00
|
|
|
StreamWriter sw = new StreamWriter (stream);
|
|
|
|
|
|
|
|
sw.WriteLine ("// Generated File. Do not modify.");
|
|
|
|
sw.WriteLine ("// <c> 2001 Mike Kestner");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
sw.WriteLine ("namespace " + ns + " {");
|
2002-01-04 02:02:28 +00:00
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
if (elem.GetAttribute("type") == "flags") {
|
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t[Flags]");
|
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine ("\tpublic enum " + Name + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
|
|
|
if (node.Name != "member") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement member = (XmlElement) node;
|
|
|
|
sw.Write ("\t\t" + member.GetAttribute("name"));
|
|
|
|
if (member.HasAttribute("value")) {
|
|
|
|
sw.WriteLine (" = " + member.GetAttribute("value") + ",");
|
|
|
|
} else {
|
|
|
|
sw.WriteLine (",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine ("\t}");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("}");
|
|
|
|
|
|
|
|
sw.Flush();
|
|
|
|
sw.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|