mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-09 00:13:20 +02:00
2003-09-14 Mike Kestner <mkestner@ximian.com>
* Makefile.in : add a gen-clean target to clean all but glue/parser. * generator/Signal.cs : use restructured SignalHandler. * generator/SignalHandler.cs (GetName): break up this monument to structured programming. svn path=/trunk/gtk-sharp/; revision=18099
This commit is contained in:
parent
a7b7003cbb
commit
60e3c167cb
@ -1,3 +1,10 @@
|
|||||||
|
2003-09-14 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
|
* Makefile.in : add a gen-clean target to clean all but glue/parser.
|
||||||
|
* generator/Signal.cs : use restructured SignalHandler.
|
||||||
|
* generator/SignalHandler.cs (GetName): break up this monument to
|
||||||
|
structured programming.
|
||||||
|
|
||||||
2003-09-12 Mike Kestner <mkestner@ximian.com>
|
2003-09-12 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
* generator/Parameters.cs (CreateSignature): begin refactoring this
|
* generator/Parameters.cs (CreateSignature): begin refactoring this
|
||||||
|
@ -32,6 +32,11 @@ clean:
|
|||||||
$(MAKE) -C $$i clean || exit 1; \
|
$(MAKE) -C $$i clean || exit 1; \
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
gen-clean:
|
||||||
|
for i in $(DIRS); do \
|
||||||
|
$(MAKE) -C $$i clean || exit 1; \
|
||||||
|
done;
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
for i in $(NATIVE_DIRS); do \
|
for i in $(NATIVE_DIRS); do \
|
||||||
$(MAKE) -C $$i distclean || exit 1; \
|
$(MAKE) -C $$i distclean || exit 1; \
|
||||||
|
@ -13,11 +13,11 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
public class Signal {
|
public class Signal {
|
||||||
|
|
||||||
private string marsh;
|
|
||||||
private string name;
|
private string name;
|
||||||
private XmlElement elem;
|
private XmlElement elem;
|
||||||
private Parameters parms;
|
private Parameters parms;
|
||||||
private ClassBase container_type;
|
private ClassBase container_type;
|
||||||
|
SignalHandler sig_handler;
|
||||||
|
|
||||||
public Signal (XmlElement elem, ClassBase container_type)
|
public Signal (XmlElement elem, ClassBase container_type)
|
||||||
{
|
{
|
||||||
@ -26,6 +26,7 @@ namespace GtkSharp.Generation {
|
|||||||
if (elem["parameters"] != null)
|
if (elem["parameters"] != null)
|
||||||
parms = new Parameters (elem["parameters"], container_type.NS);
|
parms = new Parameters (elem["parameters"], container_type.NS);
|
||||||
this.container_type = container_type;
|
this.container_type = container_type;
|
||||||
|
sig_handler = new SignalHandler (elem, container_type.NS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name {
|
public string Name {
|
||||||
@ -39,8 +40,7 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
public bool Validate ()
|
public bool Validate ()
|
||||||
{
|
{
|
||||||
marsh = SignalHandler.GetName(elem, container_type.NS, false);
|
if (Name == "" || !sig_handler.Validate ()) {
|
||||||
if ((Name == "") || (marsh == "")) {
|
|
||||||
Console.Write ("bad signal " + Name);
|
Console.Write ("bad signal " + Name);
|
||||||
Statistics.ThrottledCount++;
|
Statistics.ThrottledCount++;
|
||||||
return false;
|
return false;
|
||||||
@ -67,7 +67,7 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
private string GetHandlerName (out string argsname)
|
private string GetHandlerName (out string argsname)
|
||||||
{
|
{
|
||||||
if (marsh.EndsWith (".voidObjectSignal")) {
|
if (sig_handler.Name == "voidObjectSignal") {
|
||||||
argsname = "System.EventArgs";
|
argsname = "System.EventArgs";
|
||||||
return "EventHandler";
|
return "EventHandler";
|
||||||
}
|
}
|
||||||
@ -131,7 +131,8 @@ namespace GtkSharp.Generation {
|
|||||||
else
|
else
|
||||||
ns = implementor.NS;
|
ns = implementor.NS;
|
||||||
|
|
||||||
string qual_marsh = SignalHandler.GetName(elem, ns, container_type.DoGenerate);
|
sig_handler.Generate (ns);
|
||||||
|
string qual_marsh = ns + "Sharp." + sig_handler.Name;
|
||||||
|
|
||||||
string argsname;
|
string argsname;
|
||||||
string handler = GenHandler (out argsname);
|
string handler = GenHandler (out argsname);
|
||||||
|
@ -13,84 +13,100 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
public class SignalHandler {
|
public class SignalHandler {
|
||||||
|
|
||||||
public static string GetName(XmlElement sig, string ns, bool generate)
|
XmlElement sig;
|
||||||
|
string ns;
|
||||||
|
string retval = "";
|
||||||
|
string s_ret = "";
|
||||||
|
string p_ret = "";
|
||||||
|
Parameters parms = null;
|
||||||
|
|
||||||
|
public SignalHandler (XmlElement sig, string ns)
|
||||||
|
{
|
||||||
|
this.sig = sig;
|
||||||
|
this.ns = ns;
|
||||||
|
XmlElement params_elem = sig["parameters"] as XmlElement;
|
||||||
|
if (params_elem != null)
|
||||||
|
parms = new Parameters (params_elem, ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Validate ()
|
||||||
{
|
{
|
||||||
XmlElement ret_elem = sig["return-type"];
|
XmlElement ret_elem = sig["return-type"];
|
||||||
if (ret_elem == null) {
|
if (ret_elem == null) {
|
||||||
Console.Write("Missing return-type ");
|
Console.Write("Missing return-type ");
|
||||||
return "";
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string retval = ret_elem.GetAttribute("type");
|
retval = ret_elem.GetAttribute("type");
|
||||||
if (retval == "") {
|
if (retval == "") {
|
||||||
Console.Write("Invalid return-type ");
|
Console.Write("Invalid return-type ");
|
||||||
return "";
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SymbolTable table = SymbolTable.Table;
|
s_ret = SymbolTable.Table.GetCSType(retval);
|
||||||
|
p_ret = SymbolTable.Table.GetMarshalReturnType(retval);
|
||||||
string s_ret = table.GetCSType(retval);
|
|
||||||
string p_ret = table.GetMarshalReturnType(retval);
|
|
||||||
if ((s_ret == "") || (p_ret == "")) {
|
if ((s_ret == "") || (p_ret == "")) {
|
||||||
Console.Write("Funky type: " + retval);
|
Console.Write("Funky type: " + retval);
|
||||||
return "";
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string key = retval;
|
if (parms == null || !parms.Validate ()) {
|
||||||
string pinv = "";
|
|
||||||
string name = table.GetName(retval);
|
|
||||||
int pcnt = 0;
|
|
||||||
|
|
||||||
ArrayList parms = new ArrayList();
|
|
||||||
|
|
||||||
XmlElement params_elem = sig["parameters"];
|
|
||||||
if (params_elem == null) {
|
|
||||||
Console.Write("Missing parameters ");
|
Console.Write("Missing parameters ");
|
||||||
return "";
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ISig {
|
||||||
|
get {
|
||||||
|
string result = "";
|
||||||
|
for (int i = 0; i < parms.Count; i++) {
|
||||||
|
if (i > 0)
|
||||||
|
result += ", ";
|
||||||
|
|
||||||
|
result += (parms[i].MarshalType + " arg" + i);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (XmlNode parm in params_elem.ChildNodes) {
|
private string BaseName {
|
||||||
if (!(parm is XmlElement) || parm.Name != "parameter") continue;
|
get {
|
||||||
|
string result = SymbolTable.Table.GetName (retval);
|
||||||
|
for (int i = 0; i < parms.Count; i++) {
|
||||||
|
if (parms[i].Generatable is ObjectGen || parms[i].Generatable is InterfaceGen) {
|
||||||
|
result += "Object";
|
||||||
|
} else {
|
||||||
|
result += SymbolTable.Table.GetName(parms[i].CType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
XmlElement elem = (XmlElement) parm;
|
public string Name {
|
||||||
string type = elem.GetAttribute("type");
|
get {
|
||||||
string ptype = table.GetMarshalType(type);
|
return BaseName + "Signal";
|
||||||
if (ptype == "") {
|
}
|
||||||
Console.Write("Funky type: " + type);
|
}
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pcnt > 0) {
|
|
||||||
pinv += ", ";
|
|
||||||
}
|
|
||||||
|
|
||||||
pinv += (ptype + " arg" + pcnt);
|
public void Generate (string implementor_ns)
|
||||||
parms.Add(type);
|
{
|
||||||
if (table.IsObject(type) || table.IsInterface(type)) {
|
SymbolTable table = SymbolTable.Table;
|
||||||
name += "Object";
|
|
||||||
key += "Object";
|
|
||||||
} else {
|
|
||||||
name += table.GetName(type);
|
|
||||||
key += type;
|
|
||||||
}
|
|
||||||
pcnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
String sname = name + "Signal";
|
string sname = Name;
|
||||||
String dname = name + "Delegate";
|
string dname = BaseName + "Delegate";
|
||||||
String cbname = name + "Callback";
|
string cbname = BaseName + "Callback";
|
||||||
|
|
||||||
if (!generate)
|
|
||||||
return ns + "." + sname;
|
|
||||||
|
|
||||||
char sep = Path.DirectorySeparatorChar;
|
char sep = Path.DirectorySeparatorChar;
|
||||||
String dir = ".." + sep + ns.ToLower() + sep + "generated";
|
String dir = ".." + sep + implementor_ns.ToLower() + sep + "generated";
|
||||||
|
|
||||||
if (!Directory.Exists(dir)) {
|
if (!Directory.Exists(dir)) {
|
||||||
Directory.CreateDirectory(dir);
|
Directory.CreateDirectory(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
String filename = dir + sep + ns + "Sharp." + sname + ".cs";
|
String filename = dir + sep + implementor_ns + "Sharp." + sname + ".cs";
|
||||||
|
|
||||||
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
||||||
StreamWriter sw = new StreamWriter (stream);
|
StreamWriter sw = new StreamWriter (stream);
|
||||||
@ -98,14 +114,14 @@ namespace GtkSharp.Generation {
|
|||||||
sw.WriteLine ("// Generated File. Do not modify.");
|
sw.WriteLine ("// Generated File. Do not modify.");
|
||||||
sw.WriteLine ("// <c> 2001-2002 Mike Kestner");
|
sw.WriteLine ("// <c> 2001-2002 Mike Kestner");
|
||||||
sw.WriteLine ();
|
sw.WriteLine ();
|
||||||
sw.WriteLine("namespace " + ns + "Sharp {");
|
sw.WriteLine("namespace " + implementor_ns + "Sharp {");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
sw.WriteLine("\tusing System;");
|
sw.WriteLine("\tusing System;");
|
||||||
sw.WriteLine("\tusing System.Runtime.InteropServices;");
|
sw.WriteLine("\tusing System.Runtime.InteropServices;");
|
||||||
sw.WriteLine("\tusing GtkSharp;");
|
sw.WriteLine("\tusing GtkSharp;");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
sw.Write("\tinternal delegate " + p_ret + " ");
|
sw.Write("\tinternal delegate " + p_ret + " ");
|
||||||
sw.WriteLine(dname + "(" + pinv + ", int key);");
|
sw.WriteLine(dname + "(" + ISig + ", int key);");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
sw.WriteLine("\tinternal class " + sname + " : SignalCallback {");
|
sw.WriteLine("\tinternal class " + sname + " : SignalCallback {");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
@ -115,7 +131,7 @@ namespace GtkSharp.Generation {
|
|||||||
sw.WriteLine("\t\tprivate uint _HandlerID;");
|
sw.WriteLine("\t\tprivate uint _HandlerID;");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
sw.Write("\t\tprivate static " + p_ret + " ");
|
sw.Write("\t\tprivate static " + p_ret + " ");
|
||||||
sw.WriteLine(cbname + "(" + pinv + ", int key)");
|
sw.WriteLine(cbname + "(" + ISig + ", int key)");
|
||||||
sw.WriteLine("\t\t{");
|
sw.WriteLine("\t\t{");
|
||||||
sw.WriteLine("\t\t\tif (!_Instances.Contains(key))");
|
sw.WriteLine("\t\t\tif (!_Instances.Contains(key))");
|
||||||
sw.WriteLine("\t\t\t\tthrow new Exception(\"Unexpected signal key \" + key);");
|
sw.WriteLine("\t\t\t\tthrow new Exception(\"Unexpected signal key \" + key);");
|
||||||
@ -133,7 +149,7 @@ namespace GtkSharp.Generation {
|
|||||||
}
|
}
|
||||||
for (int idx=1; idx < parms.Count; idx++) {
|
for (int idx=1; idx < parms.Count; idx++) {
|
||||||
// sw.WriteLine("\t\t\tConsole.WriteLine (\"" + sname + " arg{0}: \" + arg{0});", idx);
|
// sw.WriteLine("\t\t\tConsole.WriteLine (\"" + sname + " arg{0}: \" + arg{0});", idx);
|
||||||
string ctype = (string) parms[idx];
|
string ctype = parms[idx].CType;
|
||||||
ClassBase wrapper = table.GetClassGen (ctype);
|
ClassBase wrapper = table.GetClassGen (ctype);
|
||||||
if ((wrapper != null && !(wrapper is StructBase)) || table.IsManuallyWrapped (ctype)) {
|
if ((wrapper != null && !(wrapper is StructBase)) || table.IsManuallyWrapped (ctype)) {
|
||||||
sw.WriteLine("\t\t\tif (arg{0} == IntPtr.Zero)", idx);
|
sw.WriteLine("\t\t\tif (arg{0} == IntPtr.Zero)", idx);
|
||||||
@ -199,8 +215,6 @@ namespace GtkSharp.Generation {
|
|||||||
sw.WriteLine("\t}");
|
sw.WriteLine("\t}");
|
||||||
sw.WriteLine("}");
|
sw.WriteLine("}");
|
||||||
sw.Close();
|
sw.Close();
|
||||||
|
|
||||||
return ns + "Sharp." + sname;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user