2002-01-06 13:33:25 +00:00
|
|
|
// GtkSharp.Generation.ObjectGen.cs - The Object Generatable.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
2002-05-23 23:43:25 +00:00
|
|
|
// (c) 2001-2002 Mike Kestner
|
2002-01-06 13:33:25 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
2002-02-03 03:44:10 +00:00
|
|
|
using System.Collections;
|
2002-01-06 13:33:25 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
public class ObjectGen : GenBase, IGeneratable {
|
2002-01-06 13:33:25 +00:00
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
private ArrayList ctors = new ArrayList();
|
|
|
|
private Hashtable props = new Hashtable();
|
|
|
|
private Hashtable sigs = new Hashtable();
|
|
|
|
private Hashtable methods = new Hashtable();
|
|
|
|
|
|
|
|
public ObjectGen (string ns, XmlElement elem) : base (ns, elem)
|
|
|
|
{
|
2002-01-06 13:33:25 +00:00
|
|
|
foreach (XmlNode node in elem.ChildNodes) {
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
XmlElement member = (XmlElement) node;
|
|
|
|
|
|
|
|
switch (node.Name) {
|
|
|
|
case "field":
|
|
|
|
case "callback":
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.IgnoreCount++;
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
case "constructor":
|
2002-05-23 23:43:25 +00:00
|
|
|
ctors.Add (new Ctor (ns, member));
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
case "method":
|
2002-05-23 23:43:25 +00:00
|
|
|
methods.Add (member.GetAttribute ("name"), new Method (ns, member));
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
case "property":
|
2002-05-23 23:43:25 +00:00
|
|
|
props.Add (member.GetAttribute ("name"), new Property (member));
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
case "signal":
|
2002-05-23 23:43:25 +00:00
|
|
|
sigs.Add (member.GetAttribute ("name"), new Signal (ns, member));
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
default:
|
2002-05-23 23:43:25 +00:00
|
|
|
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
|
2002-01-06 13:33:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string MarshalType {
|
|
|
|
get {
|
|
|
|
return "IntPtr";
|
2002-02-03 03:44:10 +00:00
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string CallByName (string var_name)
|
|
|
|
{
|
|
|
|
return var_name + ".Handle";
|
|
|
|
}
|
|
|
|
|
|
|
|
public string FromNative(string var)
|
|
|
|
{
|
|
|
|
return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
private ObjectGen Parent {
|
|
|
|
get {
|
|
|
|
string parent = Elem.GetAttribute("parent");
|
|
|
|
return SymbolTable.GetObjectGen(parent);
|
2002-02-15 01:08:57 +00:00
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Generate ()
|
|
|
|
{
|
|
|
|
StreamWriter sw = CreateWriter ();
|
2002-02-15 01:08:57 +00:00
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
sw.WriteLine ("\tusing System.Collections;");
|
|
|
|
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
sw.Write ("\tpublic class " + Name);
|
|
|
|
string cs_parent = SymbolTable.GetCSType(Elem.GetAttribute("parent"));
|
|
|
|
if (cs_parent != "")
|
|
|
|
sw.Write (" : " + cs_parent);
|
|
|
|
sw.WriteLine (" {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
|
|
|
GenCtors (sw);
|
|
|
|
GenProperties (sw);
|
|
|
|
GenSignals (sw);
|
|
|
|
GenMethods (sw);
|
|
|
|
|
|
|
|
char sep = Path.DirectorySeparatorChar;
|
|
|
|
string custom = ".." + sep + Namespace.ToLower() + sep + Name + ".custom";
|
2002-05-02 23:29:33 +00:00
|
|
|
if (File.Exists(custom)) {
|
|
|
|
FileStream custstream = new FileStream (custom, FileMode.Open, FileAccess.Read);
|
|
|
|
StreamReader sr = new StreamReader (custstream);
|
|
|
|
sw.WriteLine (sr.ReadToEnd ());
|
|
|
|
sr.Close ();
|
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-01-06 13:33:25 +00:00
|
|
|
sw.WriteLine ("\t}");
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
CloseWriter (sw);
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.ObjectCount++;
|
2002-01-12 02:08:16 +00:00
|
|
|
}
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
private bool Validate ()
|
2002-01-12 02:08:16 +00:00
|
|
|
{
|
2002-05-23 23:43:25 +00:00
|
|
|
string parent = Elem.GetAttribute("parent");
|
|
|
|
string cs_parent = SymbolTable.GetCSType(parent);
|
|
|
|
if (cs_parent == "") {
|
|
|
|
Console.WriteLine ("Object " + Name + " Unknown parent " + parent);
|
2002-01-12 02:08:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
if (ctors != null)
|
|
|
|
foreach (Ctor ctor in ctors)
|
|
|
|
if (!ctor.Validate())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (props != null)
|
|
|
|
foreach (Property prop in props.Values)
|
|
|
|
if (!prop.Validate())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (sigs != null)
|
|
|
|
foreach (Signal sig in sigs.Values)
|
|
|
|
if (!sig.Validate())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (methods != null)
|
|
|
|
foreach (Method method in methods.Values)
|
|
|
|
if (!method.Validate())
|
|
|
|
return false;
|
|
|
|
|
2002-01-12 02:08:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-02-10 23:11:25 +00:00
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
private void GenCtors (StreamWriter sw)
|
2002-02-10 23:11:25 +00:00
|
|
|
{
|
2002-05-23 23:43:25 +00:00
|
|
|
sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
|
|
|
|
sw.WriteLine();
|
2002-02-10 23:11:25 +00:00
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
Hashtable clash_map = new Hashtable();
|
|
|
|
|
|
|
|
if (ctors != null)
|
|
|
|
foreach (Ctor ctor in ctors) {
|
|
|
|
if (ctor.Validate ())
|
|
|
|
ctor.Generate (sw, clash_map);
|
|
|
|
else
|
|
|
|
Console.WriteLine(" in Object " + Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!clash_map.ContainsKey("")) {
|
|
|
|
sw.WriteLine("\t\tprotected " + Name + "() : base(){}");
|
|
|
|
sw.WriteLine();
|
2002-02-10 23:11:25 +00:00
|
|
|
}
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void GenProperties (StreamWriter sw)
|
|
|
|
{
|
|
|
|
if (props == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
foreach (Property prop in props.Values) {
|
|
|
|
if (prop.Validate ())
|
|
|
|
prop.Generate (sw);
|
|
|
|
else
|
|
|
|
Console.WriteLine(" in Object " + Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void GenSignals (StreamWriter sw)
|
|
|
|
{
|
|
|
|
if (sigs == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sw.WriteLine("\t\tprivate Hashtable Signals = new Hashtable();");
|
2002-02-10 23:11:25 +00:00
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
foreach (Signal sig in sigs.Values) {
|
|
|
|
if (sig.Validate ())
|
|
|
|
sig.Generate (sw);
|
|
|
|
else
|
|
|
|
Console.WriteLine(" in Object " + Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void GenMethods (StreamWriter sw)
|
|
|
|
{
|
|
|
|
if (methods == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
foreach (Method method in methods.Values) {
|
|
|
|
string mname = method.Name;
|
|
|
|
if ((mname.StartsWith("Set") || mname.StartsWith("Get")) &&
|
|
|
|
(props != null) && props.ContainsKey(mname.Substring(3))) {
|
|
|
|
continue;
|
|
|
|
} else if ((sigs != null) && sigs.ContainsKey(mname)) {
|
|
|
|
method.Name = "Emit" + mname;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (method.Validate ())
|
|
|
|
method.Generate (sw);
|
|
|
|
else
|
|
|
|
Console.WriteLine(" in Object " + Name);
|
|
|
|
}
|
2002-02-10 23:11:25 +00:00
|
|
|
}
|
2002-01-06 13:33:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|