2003-02-23 Mike Kestner <mkestner@speakeasy.net>

* generator/CallbackGen.cs : suppress len params from
	  string/len pairs.
	* generator/Parameters.cs : begin the refactoring to use
	  Parameter class. Suppress len params from string/len pairs.
	*/*.custom : remove all overrides of string/len pairs
	*/*.cs : ditto.  Thanks to Alp Toker for the foundation
	  patch that this change was built upon.

svn path=/trunk/gtk-sharp/; revision=11913
This commit is contained in:
Mike Kestner 2003-02-24 03:13:08 +00:00
parent 2f10faa83d
commit 554450a33a
7 changed files with 105 additions and 121 deletions

View File

@ -1,3 +1,13 @@
2003-02-23 Mike Kestner <mkestner@speakeasy.net>
* generator/CallbackGen.cs : suppress len params from
string/len pairs.
* generator/Parameters.cs : begin the refactoring to use
Parameter class. Suppress len params from string/len pairs.
*/*.custom : remove all overrides of string/len pairs
*/*.cs : ditto. Thanks to Alp Toker for the foundation
patch that this change was built upon.
2003-02-22 Mike Kestner <mkestner@speakeasy.net>
* sources/makefile : patch from Charles Krempeaux to add

View File

@ -103,8 +103,13 @@ namespace GtkSharp.Generation {
{
string parm_name = parms[i].Name;
string ctype = parms[i].CType;
if (i > 0 && parms[i].IsLength && parms[i-1].IsString)
continue;
if ((i == count - 1) && ctype == "gpointer" && (parm_name.EndsWith ("data") || parm_name.EndsWith ("data_or_owner")))
continue;
string cstype = parms[i].CSType;
// FIXME: Too much code copy/pasted here. Refactor?
ClassBase parm_wrapper = SymbolTable.GetClassGen (ctype);

View File

@ -33,39 +33,73 @@ namespace GtkSharp.Generation {
string cstype = SymbolTable.GetCSType( elem.GetAttribute("type"));
if (cstype == "void")
cstype = "System.IntPtr";
if (elem.HasAttribute("array"))
if (elem.HasAttribute("array")) {
cstype += "[]";
cstype = cstype.Replace ("ref ", "");
}
return cstype;
}
}
public bool IsLength {
get {
return (CSType == "int" &&
(Name.EndsWith("len") || Name.EndsWith("length")));
}
}
public bool IsString {
get {
return (CSType == "string");
}
}
public string MarshalType {
get {
string type = SymbolTable.GetMarshalType( elem.GetAttribute("type"));
if (type == "void")
type = "System.IntPtr";
if (elem.HasAttribute("array")) {
type += "[]";
type = type.Replace ("ref ", "");
}
return type;
}
}
public string Name {
get {
string name = elem.GetAttribute("name");
switch (name) {
case "string":
return "str1ng";
case "event":
return "evnt";
case "object":
return "objekt";
default:
break;
}
return name;
return MangleName (elem.GetAttribute("name"));
}
}
private string MangleName(string name)
{
switch (name) {
case "string":
return "str1ng";
case "event":
return "evnt";
case "null":
return "is_null";
case "object":
return "objekt";
case "params":
return "parms";
case "ref":
return "reference";
case "in":
return "in_param";
case "out":
return "out_param";
case "fixed":
return "mfixed";
default:
break;
}
return name;
}
public string StudlyName {
get {
string name = elem.GetAttribute("name");
@ -149,15 +183,11 @@ namespace GtkSharp.Generation {
return false;
}
string type = p_elem.GetAttribute("type");
string cs_type = SymbolTable.GetCSType(type);
string m_type = SymbolTable.GetMarshalType(type);
string name = MangleName(p_elem.GetAttribute("name"));
string call_parm = SymbolTable.CallByName(type, name);
Parameter p = new Parameter (p_elem);
if ((cs_type == "") || (name == "") ||
(m_type == "") || (call_parm == "")) {
Console.Write("Name: " + name + " Type: " + type + " ");
if ((p.CSType == "") || (p.Name == "") ||
(p.MarshalType == "") || (SymbolTable.CallByName(p.CType, p.Name) == "")) {
Console.Write("Name: " + p.Name + " Type: " + p.CType + " ");
return false;
}
}
@ -172,10 +202,9 @@ namespace GtkSharp.Generation {
bool has_callback = hide_data;
bool last_was_user_data = false;
bool has_user_data = false;
string callback_type = "";
int len = 0;
XmlElement last_param = null;
Parameter last_param = null;
foreach (XmlNode parm in elem.ChildNodes) {
if (parm.Name != "parameter") {
continue;
@ -184,51 +213,49 @@ namespace GtkSharp.Generation {
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 = (XmlElement) parm;
last_param = new Parameter ((XmlElement) parm);
}
int i = 0;
Parameter prev = null;
foreach (XmlNode parm in elem.ChildNodes) {
if (parm.Name != "parameter") {
continue;
}
XmlElement p_elem = (XmlElement) parm;
string type = p_elem.GetAttribute("type");
string cs_type = SymbolTable.GetCSType(type);
if (cs_type == "void")
cs_type = "System.IntPtr";
string m_type = SymbolTable.GetMarshalType(type);
if (m_type == "void")
m_type = "System.IntPtr";
string name = MangleName(p_elem.GetAttribute("name"));
string call_parm, call_parm_name;
Parameter curr = new Parameter (p_elem);
if (SymbolTable.IsCallback (type)) {
has_callback = true;
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;
prev = curr;
i++;
continue;
}
string call_parm_name = name;
if (is_set && i == 0)
call_parm_name = "value";
else
call_parm_name = name;
string call_parm;
if (SymbolTable.IsCallback (type)) {
has_callback = true;
call_parm = SymbolTable.CallByName (type, call_parm_name + "_wrapper");
callback_type = type.Replace(".", "Sharp.") + "Wrapper";
} else
call_parm = SymbolTable.CallByName(type, call_parm_name);
if (p_elem.HasAttribute ("null_ok") && cs_type != "IntPtr" && cs_type != "System.IntPtr" && !SymbolTable.IsStruct (type))
call_parm = String.Format ("({0} != null) ? {1} : {2}", call_parm_name, call_parm, SymbolTable.IsCallback (type) ? "null" : "IntPtr.Zero");
if (p_elem.HasAttribute("array")) {
cs_type += "[]";
m_type += "[]";
cs_type = cs_type.Replace ("ref ", "");
m_type = m_type.Replace ("ref ", "");
if (p_elem.HasAttribute("array"))
call_parm = call_parm.Replace ("ref ", "");
}
if (IsVarArgs && i == (len - 1) && VAType == "length_param") {
cs_type = "params " + cs_type + "[]";
@ -268,7 +295,7 @@ namespace GtkSharp.Generation {
if (IsVarArgs && i == (len - 2) && VAType == "length_param")
{
call_string += MangleName(last_param.GetAttribute("name")) + ".Length";
call_string += last_param.Name + ".Length";
last_was_user_data = false;
}
else
@ -289,6 +316,7 @@ namespace GtkSharp.Generation {
call_string += call_parm;
}
import_sig += (m_type + " " + name);
prev = curr;
i++;
}
@ -313,14 +341,15 @@ namespace GtkSharp.Generation {
}
XmlElement p_elem = (XmlElement) parm;
Parameter p = new Parameter (p_elem);
string c_type = p_elem.GetAttribute ("type");
string type = SymbolTable.GetCSType(c_type);
string c_type = p.CType;
string type = p.CSType;
if (is_set) {
name = "value";
} else {
name = MangleName(p_elem.GetAttribute("name"));
name = p.Name;
}
if (is_get) {
@ -345,14 +374,15 @@ namespace GtkSharp.Generation {
}
XmlElement p_elem = (XmlElement) parm;
Parameter p = new Parameter (p_elem);
string c_type = p_elem.GetAttribute ("type");
string type = SymbolTable.GetCSType(c_type);
string c_type = p.CType;
string type = p.CSType;
if (is_set) {
name = "value";
} else {
name = MangleName(p_elem.GetAttribute("name"));
name = p.Name;
}
if (SymbolTable.IsCallback (c_type)) {
@ -377,9 +407,10 @@ namespace GtkSharp.Generation {
}
XmlElement p_elem = (XmlElement) parm;
string c_type = p_elem.GetAttribute ("type");
string name = MangleName(p_elem.GetAttribute("name"));
string type = SymbolTable.GetCSType(c_type);
Parameter p = new Parameter (p_elem);
string c_type = p.CType;
string name = p.Name;
string type = p.CSType;
if (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out" && SymbolTable.IsEnum (c_type)) {
sw.WriteLine(indent + "\t\t\t" + name + " = (" + type + ") " + name + "_as_int;");
@ -476,39 +507,13 @@ namespace GtkSharp.Generation {
if (parm.Name != "parameter")
continue;
XmlElement p_elem = (XmlElement) parm;
return MangleName (p_elem.GetAttribute("name"));
Parameter p = new Parameter (p_elem);
return p.Name;
}
return null;
}
}
private string MangleName(string name)
{
switch (name) {
case "string":
return "str1ng";
case "event":
return "evnt";
case "null":
return "is_null";
case "object":
return "objekt";
case "params":
return "parms";
case "ref":
return "reference";
case "in":
return "in_param";
case "out":
return "out_param";
case "fixed":
return "mfixed";
default:
break;
}
return name;
}
}
}

View File

@ -51,9 +51,3 @@
return ret;
}
public void SetText (string new_text)
{
SetText (new_text, new_text.Length);
}

View File

@ -8,7 +8,7 @@ public int InsertText (string new_text)
{
int position = 0;
InsertText (new_text, new_text.Length, ref position);
InsertText (new_text, ref position);
return position;
}

View File

@ -1,20 +0,0 @@
//
// Pango.GlyphString.custom - Allow customization of values in the GtkAdjustment
//
// This code is inserted after the automatically generated code.
//
public void GetLogicalWidths (string text, int embedding_level, int logical_widths)
{
pango_glyph_string_get_logical_widths(ref this, text, text.Length, embedding_level, logical_widths);
}
public void XToIndex (string text, Pango.Analysis analysis, int x_pos, int index, int trailing)
{
pango_glyph_string_x_to_index(ref this, text, text.Length, ref analysis, x_pos, index, trailing);
}
public void IndexToX (string text, Pango.Analysis analysis, int index, bool trailing, int x_pos)
{
pango_glyph_string_index_to_x(ref this, text, text.Length, ref analysis, index, trailing, x_pos);
}

View File

@ -15,13 +15,3 @@ public System.Drawing.Size Size {
}
}
/// <summary> SetText Method, overloaded to not having to calculate string length </summary>
public void SetText(string text) {
SetText(text, text.Length);
}
/// <summary> SetMarkup Method, overloaded to not having to calculate string length </summary>
public void SetMarkup(string markup) {
SetText(markup, markup.Length);
}