2003-09-12 Mike Kestner <mkestner@ximian.com>
* generator/Parameters.cs (CreateSignature): begin refactoring this unholy mess. Eliminated one pass thru the param list. Eliminated prev/curr param refs. Switched to a for loop since lookbacks are required. svn path=/trunk/gtk-sharp/; revision=18050
This commit is contained in:
parent
1a0892ea8b
commit
6a16e09541
2 changed files with 42 additions and 64 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2003-09-12 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
|
* generator/Parameters.cs (CreateSignature): begin refactoring this
|
||||||
|
unholy mess. Eliminated one pass thru the param list. Eliminated
|
||||||
|
prev/curr param refs. Switched to a for loop since lookbacks are
|
||||||
|
required.
|
||||||
|
|
||||||
2003-09-11 Mike Kestner <mkestner@ximian.com>
|
2003-09-11 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
* generator/Parameters.cs : keep an ArrayList of Parameter objects
|
* generator/Parameters.cs : keep an ArrayList of Parameter objects
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace GtkSharp.Generation {
|
||||||
string cstype = SymbolTable.Table.GetCSType( elem.GetAttribute("type"));
|
string cstype = SymbolTable.Table.GetCSType( elem.GetAttribute("type"));
|
||||||
if (cstype == "void")
|
if (cstype == "void")
|
||||||
cstype = "System.IntPtr";
|
cstype = "System.IntPtr";
|
||||||
if (elem.HasAttribute("array")) {
|
if (IsArray) {
|
||||||
cstype += "[]";
|
cstype += "[]";
|
||||||
cstype = cstype.Replace ("ref ", "");
|
cstype = cstype.Replace ("ref ", "");
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,12 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsArray {
|
||||||
|
get {
|
||||||
|
return elem.HasAttribute("array");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsEllipsis {
|
public bool IsEllipsis {
|
||||||
get {
|
get {
|
||||||
return elem.HasAttribute("ellipsis");
|
return elem.HasAttribute("ellipsis");
|
||||||
|
@ -80,12 +86,18 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsUserData {
|
||||||
|
get {
|
||||||
|
return CType == "gpointer" && (Name.EndsWith ("data") || Name.EndsWith ("data_or_owner"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string MarshalType {
|
public string MarshalType {
|
||||||
get {
|
get {
|
||||||
string type = SymbolTable.Table.GetMarshalType( elem.GetAttribute("type"));
|
string type = SymbolTable.Table.GetMarshalType( elem.GetAttribute("type"));
|
||||||
if (type == "void")
|
if (type == "void")
|
||||||
type = "System.IntPtr";
|
type = "System.IntPtr";
|
||||||
if (elem.HasAttribute("array")) {
|
if (IsArray) {
|
||||||
type += "[]";
|
type += "[]";
|
||||||
type = type.Replace ("ref ", "");
|
type = type.Replace ("ref ", "");
|
||||||
}
|
}
|
||||||
|
@ -221,44 +233,19 @@ namespace GtkSharp.Generation {
|
||||||
import_sig = call_string = signature = signature_types = "";
|
import_sig = call_string = signature = signature_types = "";
|
||||||
bool need_sep = false;
|
bool need_sep = false;
|
||||||
bool has_callback = hide_data;
|
bool has_callback = hide_data;
|
||||||
bool last_was_user_data = false;
|
|
||||||
bool has_user_data = false;
|
|
||||||
|
|
||||||
SymbolTable table = SymbolTable.Table;
|
SymbolTable table = SymbolTable.Table;
|
||||||
int len = 0;
|
|
||||||
Parameter last_param = null;
|
|
||||||
foreach (XmlNode parm in elem.ChildNodes) {
|
|
||||||
if (parm.Name != "parameter") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
XmlElement p_elem = (XmlElement) parm;
|
|
||||||
if (p_elem.GetAttribute("type") == "gpointer" && (p_elem.GetAttribute("name").EndsWith ("data") || p_elem.GetAttribute("name").EndsWith ("data_or_owner")))
|
|
||||||
has_user_data = true;
|
|
||||||
len++;
|
|
||||||
last_param = new Parameter ((XmlElement) parm);
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
for (int i = 0; i < Count; i++) {
|
||||||
Parameter prev = null;
|
|
||||||
|
|
||||||
foreach (XmlNode parm in elem.ChildNodes) {
|
string type = this [i].CType;
|
||||||
if (parm.Name != "parameter") {
|
string cs_type = this [i].CSType;
|
||||||
continue;
|
string m_type = this [i].MarshalType;
|
||||||
}
|
string name = this [i].Name;
|
||||||
|
|
||||||
XmlElement p_elem = (XmlElement) parm;
|
if (i > 0 && this [i - 1].IsString && this [i].IsLength) {
|
||||||
Parameter curr = new Parameter (p_elem);
|
call_string += ", " + this [i - 1].Name + ".Length";
|
||||||
|
|
||||||
string type = curr.CType;
|
|
||||||
string cs_type = curr.CSType;
|
|
||||||
string m_type = curr.MarshalType;
|
|
||||||
string name = curr.Name;
|
|
||||||
|
|
||||||
if (prev != null && prev.IsString && curr.IsLength) {
|
|
||||||
call_string += ", " + prev.Name + ".Length";
|
|
||||||
import_sig += ", " + m_type + " " + name;
|
import_sig += ", " + m_type + " " + name;
|
||||||
prev = curr;
|
|
||||||
i++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,13 +260,13 @@ namespace GtkSharp.Generation {
|
||||||
} else
|
} else
|
||||||
call_parm = table.CallByName(type, call_parm_name);
|
call_parm = table.CallByName(type, call_parm_name);
|
||||||
|
|
||||||
if (p_elem.HasAttribute ("null_ok") && cs_type != "IntPtr" && cs_type != "System.IntPtr" && !table.IsStruct (type))
|
if (this [i].NullOk && cs_type != "IntPtr" && cs_type != "System.IntPtr" && !table.IsStruct (type))
|
||||||
call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, table.IsCallback (type) ? "null" : "IntPtr.Zero");
|
call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, table.IsCallback (type) ? "null" : "IntPtr.Zero");
|
||||||
|
|
||||||
if (p_elem.HasAttribute("array"))
|
if (this [i].IsArray)
|
||||||
call_parm = call_parm.Replace ("ref ", "");
|
call_parm = call_parm.Replace ("ref ", "");
|
||||||
|
|
||||||
if (IsVarArgs && i == (len - 1) && VAType == "length_param") {
|
if (IsVarArgs && i == (Count - 1) && VAType == "length_param") {
|
||||||
cs_type = "params " + cs_type + "[]";
|
cs_type = "params " + cs_type + "[]";
|
||||||
m_type += "[]";
|
m_type += "[]";
|
||||||
}
|
}
|
||||||
|
@ -287,7 +274,7 @@ namespace GtkSharp.Generation {
|
||||||
if (need_sep) {
|
if (need_sep) {
|
||||||
call_string += ", ";
|
call_string += ", ";
|
||||||
import_sig += ", ";
|
import_sig += ", ";
|
||||||
if (!(type == "GError**" || last_was_user_data) && !(IsVarArgs && i == (len - 1) && VAType == "length_param"))
|
if (type != "GError**" && !(IsVarArgs && i == (Count - 1) && VAType == "length_param"))
|
||||||
{
|
{
|
||||||
signature += ", ";
|
signature += ", ";
|
||||||
signature_types += ":";
|
signature_types += ":";
|
||||||
|
@ -296,52 +283,39 @@ namespace GtkSharp.Generation {
|
||||||
need_sep = true;
|
need_sep = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_elem.HasAttribute("pass_as")) {
|
if (this [i].PassAs != "") {
|
||||||
string pass_as = p_elem.GetAttribute("pass_as");
|
signature += this [i].PassAs + " ";
|
||||||
signature += pass_as + " ";
|
|
||||||
// We only need to do this for value types
|
// We only need to do this for value types
|
||||||
if (type != "GError**" && m_type != "IntPtr" && m_type != "System.IntPtr")
|
if (type != "GError**" && m_type != "IntPtr" && m_type != "System.IntPtr")
|
||||||
{
|
{
|
||||||
import_sig += pass_as + " ";
|
import_sig += this [i].PassAs + " ";
|
||||||
call_string += pass_as + " ";
|
call_string += this [i].PassAs + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (table.IsEnum (type))
|
if (table.IsEnum (type))
|
||||||
call_parm = name + "_as_int";
|
call_parm = name + "_as_int";
|
||||||
}
|
} else if (type == "GError**") {
|
||||||
else if (type == "GError**")
|
|
||||||
{
|
|
||||||
call_string += "out ";
|
call_string += "out ";
|
||||||
import_sig += "out ";
|
import_sig += "out ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsVarArgs && i == (len - 2) && VAType == "length_param")
|
if (IsVarArgs && i == (Count - 2) && VAType == "length_param") {
|
||||||
{
|
call_string += this [Count - 1].Name + ".Length";
|
||||||
call_string += last_param.Name + ".Length";
|
} else {
|
||||||
last_was_user_data = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(type == "GError**" || (has_callback && (type == "gpointer" || type == "void*") && (i == Count - 1) && (name.EndsWith ("data") || name.EndsWith ("data_or_owner"))))) {
|
if (!(type == "GError**" || (has_callback && (type == "gpointer" || type == "void*") && (i == Count - 1) && (name.EndsWith ("data") || name.EndsWith ("data_or_owner"))))) {
|
||||||
signature += (cs_type + " " + name);
|
signature += (cs_type + " " + name);
|
||||||
signature_types += cs_type;
|
signature_types += cs_type;
|
||||||
last_was_user_data = false;
|
|
||||||
} else if (type == "GError**") {
|
} else if (type == "GError**") {
|
||||||
call_parm = call_parm.Replace (name, "error");
|
call_parm = call_parm.Replace (name, "error");
|
||||||
last_was_user_data = false;
|
|
||||||
} else if ((type == "gpointer" || type == "void*") && (i == Count - 1) && (name.EndsWith ("data") || name.EndsWith ("data_or_owner"))) {
|
} else if ((type == "gpointer" || type == "void*") && (i == Count - 1) && (name.EndsWith ("data") || name.EndsWith ("data_or_owner"))) {
|
||||||
call_parm = "IntPtr.Zero";
|
call_parm = "IntPtr.Zero";
|
||||||
last_was_user_data = true;
|
}
|
||||||
} else
|
|
||||||
last_was_user_data = false;
|
|
||||||
|
|
||||||
call_string += call_parm;
|
call_string += call_parm;
|
||||||
}
|
}
|
||||||
if (table.IsCallback (type))
|
if (table.IsCallback (type))
|
||||||
m_type = impl_ns + "Sharp" + m_type.Substring(m_type.IndexOf("."));
|
m_type = impl_ns + "Sharp" + m_type.Substring(m_type.IndexOf("."));
|
||||||
import_sig += (m_type + " " + name);
|
import_sig += (m_type + " " + name);
|
||||||
prev = curr;
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: lame
|
// FIXME: lame
|
||||||
|
@ -357,11 +331,8 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public void Initialize (StreamWriter sw, bool is_get, bool is_set, string indent)
|
public void Initialize (StreamWriter sw, bool is_get, bool is_set, string indent)
|
||||||
{
|
{
|
||||||
foreach (XmlNode parm in elem.ChildNodes) {
|
foreach (Parameter p in param_list) {
|
||||||
if (parm.Name != "parameter")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Parameter p = new Parameter ((XmlElement) parm);
|
|
||||||
IGeneratable gen = p.Generatable;
|
IGeneratable gen = p.Generatable;
|
||||||
string name = p.Name;
|
string name = p.Name;
|
||||||
if (is_set)
|
if (is_set)
|
||||||
|
|
Loading…
Reference in a new issue