[Gtk-sharp-list] patch fixing override issue for gtk-sharp/generator/Method.cs

Martin Willemoes Hansen mwh@sysrq.dk
Thu, 21 Aug 2003 12:23:34 +0200


--=-KjM3YC5iCAQXrapfcgiz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Tue, 2003-08-19 at 06:30, Mike Kestner wrote:
> On Thu, 2003-08-14 at 08:55, Martin Willemoes Hansen wrote:
> > 
> > BTW. How can I rename a field? like I have a field named base .. that I
> > would like to rename to Base. Is this functionality implemented?
> > I guess I should look at the parser if it isnt.
> 
> Doesn't look like field targets are handled in Metadata.pm.  It should
> be easy to add.  You basically have to add field support to parseClass,
> and then handle the field nodes in fixupNamespace.

I took a stab at it but I could not make it work :( Instead I patched
generator/StructBase.cs to check if the field name is a Keyword and
uppercase the first letter if it is.

Hope it can be used.
-- 
Martin Willemoes Hansen

--------------------------------------------------------
E-Mail	mwh@sysrq.dk	Website	mwh.sysrq.dk
IRC     MWH, freenode.net
--------------------------------------------------------               


--=-KjM3YC5iCAQXrapfcgiz
Content-Disposition: attachment; filename=StructBase.cs.diff
Content-Type: text/plain; name=StructBase.cs.diff; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

? StructBase.cs.diff
Index: StructBase.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/generator/StructBase.cs,v
retrieving revision 1.37
diff -u -r1.37 StructBase.cs
--- StructBase.cs	23 Jul 2003 17:19:19 -0000	1.37
+++ StructBase.cs	21 Aug 2003 10:32:10 -0000
@@ -146,12 +146,41 @@
 			return true;
 		}
 
+		string ConvertKeyWord (string keyword)
+		{
+			return Char.ToUpper (keyword [0]) + keyword.Substring (1);
+		}
+
+		bool IsKeyWord (string word)
+		{
+			switch (word) {
+			case "abstract": case "base": case "bool": case "break": case "byte":
+			case "case": case "catch": case "char": case "checked": case "class":
+			case "const": case "continue": case "decimal": case "default": 
+			case "delegate": case "do": case "double": case "else": case "enum": 
+			case "event": case "explicit": case "extern": case "false": 
+			case "finally": case "fixed": case "float": case "for": case "foreach":
+			case "goto": case "if": case "implicit": case "in": case "int": 
+			case "interface": case "internal": case "is": case "lock": case "long":
+			case "namespace": case "new": case "null": case "object": 
+			case "operator": case "out": case "override": case "params": 
+			case "private": case "protected": case "public": case "readonly":
+			case "ref": case "return": case "sbyte": case "sealed": case "short":
+			case "sizeof": case "static": case "string": case "struct": 
+			case "switch": case "this": case "throw": case "true": case "try":
+			case "typeof": case "uint": case "ulong": case "unchecked": 
+			case "unsafe": case "ushort": case "using": case "virtual": 
+			case "void": case "while": return true;
+			default: return false;
+			}
+		}
+
 		protected bool GenField (XmlElement field, StreamWriter sw)
 		{
 			string c_type, type, name;
 			if (!GetFieldInfo (field, out c_type, out type, out name))
 				return false;
-			sw.WriteLine ("\t\tpublic {0} {1};", type, name);
+			sw.WriteLine ("\t\tpublic {0} {1};", type, IsKeyWord (name) ? ConvertKeyWord (name) : name);
 
 			if (field.HasAttribute("array_len"))
 				Console.WriteLine ("warning: array field {0}.{1} probably incorrectly generated", QualifiedName, name);

--=-KjM3YC5iCAQXrapfcgiz--