2003-06-14 Mike Kestner <mkestner@speakeasy.net>
* CallbackGen.cs : rework for internal callback helpers, pass NS to parms ctor * Ctor.cs : pass NS to parms ctor * Method.cs : pass NS to parms ctor * Parameters.cs : refactoring, plus rework for internal callback helpers. * Signal.cs : pass NS to parms ctor svn path=/trunk/gtk-sharp/; revision=15385
This commit is contained in:
parent
e1036250bb
commit
bbf727c80e
6 changed files with 70 additions and 76 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2003-06-14 Mike Kestner <mkestner@speakeasy.net>
|
||||
|
||||
* CallbackGen.cs : rework for internal callback helpers,
|
||||
pass NS to parms ctor
|
||||
* Ctor.cs : pass NS to parms ctor
|
||||
* Method.cs : pass NS to parms ctor
|
||||
* Parameters.cs : refactoring, plus rework for internal
|
||||
callback helpers.
|
||||
* Signal.cs : pass NS to parms ctor
|
||||
|
||||
2003-06-14 Mike Kestner <mkestner@speakeasy.net>
|
||||
|
||||
* parser/gapi2xml.pl : some whitespace parsing cleanup
|
||||
|
|
|
@ -17,44 +17,44 @@ namespace GtkSharp.Generation {
|
|||
public CallbackGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
||||
{
|
||||
if (elem ["parameters"] != null)
|
||||
parms = new Parameters (elem ["parameters"]);
|
||||
parms = new Parameters (elem ["parameters"], NS);
|
||||
}
|
||||
|
||||
public String MarshalType {
|
||||
public string MarshalType {
|
||||
get
|
||||
{
|
||||
return NS + "Sharp." + Name + "Native";
|
||||
}
|
||||
}
|
||||
|
||||
public String MarshalReturnType {
|
||||
public string MarshalReturnType {
|
||||
get
|
||||
{
|
||||
return MarshalType;
|
||||
}
|
||||
}
|
||||
|
||||
public String CallByName (String var_name)
|
||||
public string CallByName (string var_name)
|
||||
{
|
||||
return var_name + ".NativeDelegate";
|
||||
}
|
||||
|
||||
public String FromNative(String var)
|
||||
public string FromNative(string var)
|
||||
{
|
||||
return var;
|
||||
}
|
||||
|
||||
public String FromNativeReturn(String var)
|
||||
public string FromNativeReturn(string var)
|
||||
{
|
||||
return FromNative (var);
|
||||
}
|
||||
|
||||
public virtual String ToNativeReturn(String var)
|
||||
public virtual string ToNativeReturn(string var)
|
||||
{
|
||||
return CallByName (var);
|
||||
}
|
||||
|
||||
public void GenWrapper (string ns)
|
||||
public string GenWrapper (string ns)
|
||||
{
|
||||
char sep = Path.DirectorySeparatorChar;
|
||||
string dir = ".." + sep + ns.ToLower() + sep + "generated";
|
||||
|
@ -99,7 +99,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine ("\tinternal delegate " + m_ret + " " + wrapper + "(" + import_sig + ");");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\tpublic class " + Name + "Wrapper : GLib.DelegateWrapper {");
|
||||
sw.WriteLine ("\tinternal class " + Name + "Wrapper : GLib.DelegateWrapper {");
|
||||
if (m_ret != "void") {
|
||||
if (table.IsEnum (rettype)) {
|
||||
sw.WriteLine ("\t\tstatic int _dummy;");
|
||||
|
@ -174,7 +174,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine ("\t\t}");
|
||||
sw.WriteLine ();
|
||||
|
||||
sw.WriteLine ("\t\tpublic {0} NativeDelegate;", wrapper);
|
||||
sw.WriteLine ("\t\tinternal {0} NativeDelegate;", wrapper);
|
||||
sw.WriteLine ("\t\tprotected {0} _managed;", NS + "." + Name);
|
||||
sw.WriteLine ();
|
||||
|
||||
|
@ -189,6 +189,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
sw.WriteLine ("#endregion");
|
||||
CloseWriter (sw);
|
||||
return ns + "Sharp." + Name + "Wrapper";
|
||||
}
|
||||
|
||||
public void Generate ()
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace GtkSharp.Generation {
|
|||
this.container_type = container_type;
|
||||
XmlElement parms_elem = elem ["parameters"];
|
||||
if (parms_elem != null)
|
||||
parms = new Parameters (parms_elem);
|
||||
parms = new Parameters (parms_elem, container_type.NS);
|
||||
if (elem.HasAttribute ("preferred"))
|
||||
preferred = true;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace GtkSharp.Generation {
|
|||
{
|
||||
this.elem = elem;
|
||||
if (elem["parameters"] != null)
|
||||
parms = new Parameters (elem["parameters"]);
|
||||
parms = new Parameters (elem["parameters"], container_type.NS);
|
||||
this.container_type = container_type;
|
||||
this.name = elem.GetAttribute("name");
|
||||
if (name == "GetType")
|
||||
|
|
|
@ -41,6 +41,12 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public IGeneratable Generatable {
|
||||
get {
|
||||
return SymbolTable.Table[CType];
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLength {
|
||||
get {
|
||||
return (CSType == "int" &&
|
||||
|
@ -73,6 +79,18 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public bool NullOk {
|
||||
get {
|
||||
return elem.HasAttribute ("null_ok");
|
||||
}
|
||||
}
|
||||
|
||||
public string PassAs {
|
||||
get {
|
||||
return elem.GetAttribute ("pass_as");
|
||||
}
|
||||
}
|
||||
|
||||
private string MangleName(string name)
|
||||
{
|
||||
switch (name) {
|
||||
|
@ -118,6 +136,7 @@ namespace GtkSharp.Generation {
|
|||
public class Parameters {
|
||||
|
||||
private XmlElement elem;
|
||||
private string impl_ns;
|
||||
private string import_sig;
|
||||
private string call_string;
|
||||
private string signature;
|
||||
|
@ -125,9 +144,10 @@ namespace GtkSharp.Generation {
|
|||
private bool hide_data;
|
||||
private bool is_static;
|
||||
|
||||
public Parameters (XmlElement elem) {
|
||||
public Parameters (XmlElement elem, string impl_ns) {
|
||||
|
||||
this.elem = elem;
|
||||
this.impl_ns = impl_ns;
|
||||
}
|
||||
|
||||
public string CallString {
|
||||
|
@ -321,6 +341,8 @@ namespace GtkSharp.Generation {
|
|||
|
||||
call_string += call_parm;
|
||||
}
|
||||
if (table.IsCallback (type))
|
||||
m_type = impl_ns + "Sharp" + m_type.Substring(m_type.IndexOf("."));
|
||||
import_sig += (m_type + " " + name);
|
||||
prev = curr;
|
||||
i++;
|
||||
|
@ -339,89 +361,50 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public void Initialize (StreamWriter sw, bool is_get, bool is_set, string indent)
|
||||
{
|
||||
string name = "";
|
||||
|
||||
SymbolTable table = SymbolTable.Table;
|
||||
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
if (parm.Name != "parameter") {
|
||||
if (parm.Name != "parameter")
|
||||
continue;
|
||||
}
|
||||
|
||||
XmlElement p_elem = (XmlElement) parm;
|
||||
Parameter p = new Parameter (p_elem);
|
||||
|
||||
string c_type = p.CType;
|
||||
string type = p.CSType;
|
||||
|
||||
if (is_set) {
|
||||
Parameter p = new Parameter ((XmlElement) parm);
|
||||
IGeneratable gen = p.Generatable;
|
||||
string name = p.Name;
|
||||
if (is_set)
|
||||
name = "value";
|
||||
} else {
|
||||
name = p.Name;
|
||||
}
|
||||
|
||||
if (is_get) {
|
||||
sw.WriteLine (indent + "\t\t\t" + type + " " + name + ";");
|
||||
}
|
||||
if (is_get)
|
||||
sw.WriteLine (indent + "\t\t\t" + p.CSType + " " + name + ";");
|
||||
|
||||
if ((is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) && (table.IsObject (c_type) || table.IsOpaque (c_type) || type == "GLib.Value")) {
|
||||
sw.WriteLine(indent + "\t\t\t" + name + " = new " + type + "();");
|
||||
}
|
||||
if ((is_get || p.PassAs == "out") && (gen is ObjectGen || gen is OpaqueGen || p.CSType == "GLib.Value"))
|
||||
sw.WriteLine(indent + "\t\t\t" + name + " = new " + p.CSType + "();");
|
||||
|
||||
if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && table.IsEnum (c_type)) {
|
||||
if (p.PassAs == "out" && gen is EnumGen)
|
||||
sw.WriteLine(indent + "\t\t\tint " + name + "_as_int;");
|
||||
|
||||
if (gen is CallbackGen) {
|
||||
CallbackGen cbgen = gen as CallbackGen;
|
||||
string wrapper = cbgen.GenWrapper(impl_ns);
|
||||
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", wrapper, name);
|
||||
sw.Write (indent + "\t\t\t");
|
||||
if (p.NullOk)
|
||||
sw.Write ("if ({0} != null) ", name);
|
||||
sw.WriteLine ("{1}_wrapper = new {0} ({1}, {2});", wrapper, name, is_static ? "null" : "this");
|
||||
}
|
||||
}
|
||||
|
||||
if (ThrowsException)
|
||||
sw.WriteLine (indent + "\t\t\tIntPtr error = IntPtr.Zero;");
|
||||
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
if (parm.Name != "parameter") {
|
||||
continue;
|
||||
}
|
||||
|
||||
XmlElement p_elem = (XmlElement) parm;
|
||||
Parameter p = new Parameter (p_elem);
|
||||
|
||||
string c_type = p.CType;
|
||||
string type = p.CSType;
|
||||
|
||||
if (is_set) {
|
||||
name = "value";
|
||||
} else {
|
||||
name = p.Name;
|
||||
}
|
||||
|
||||
if (table.IsCallback (c_type)) {
|
||||
type = type.Replace(".", "Sharp.") + "Wrapper";
|
||||
|
||||
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", type, name);
|
||||
sw.Write (indent + "\t\t\t");
|
||||
if (p_elem.HasAttribute ("null_ok"))
|
||||
{
|
||||
sw.Write ("if ({0} != null) ", name);
|
||||
}
|
||||
sw.WriteLine ("{1}_wrapper = new {0} ({1}, {2});", type, name, is_static ? "null" : "this");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Finish (StreamWriter sw, string indent)
|
||||
{
|
||||
foreach (XmlNode parm in elem.ChildNodes) {
|
||||
if (parm.Name != "parameter") {
|
||||
if (parm.Name != "parameter")
|
||||
continue;
|
||||
}
|
||||
|
||||
XmlElement p_elem = (XmlElement) parm;
|
||||
Parameter p = new Parameter (p_elem);
|
||||
string c_type = p.CType;
|
||||
string name = p.Name;
|
||||
string type = p.CSType;
|
||||
Parameter p = new Parameter ((XmlElement) parm);
|
||||
|
||||
if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && SymbolTable.Table.IsEnum (c_type)) {
|
||||
sw.WriteLine(indent + "\t\t\t" + name + " = (" + type + ") " + name + "_as_int;");
|
||||
if (p.PassAs == "out" && p.Generatable is EnumGen) {
|
||||
sw.WriteLine(indent + "\t\t\t" + p.Name + " = (" + p.CSType + ") " + p.Name + "_as_int;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace GtkSharp.Generation {
|
|||
this.elem = elem;
|
||||
this.name = elem.GetAttribute ("name");
|
||||
if (elem["parameters"] != null)
|
||||
parms = new Parameters (elem["parameters"]);
|
||||
parms = new Parameters (elem["parameters"], container_type.NS);
|
||||
this.container_type = container_type;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue