1
// GtkSharp.Generation.StructField.cs - The Structure Field generation
4
// Author: Mike Kestner <mkestner@ximian.com>
6
// Copyright (c) 2004-2005 Novell, Inc.
8
// This program is free software; you can redistribute it and/or
9
// modify it under the terms of version 2 of the GNU General Public
10
// License as published by the Free Software Foundation.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// General Public License for more details.
17
// You should have received a copy of the GNU General Public
18
// License along with this program; if not, write to the
19
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
// Boston, MA 02111-1307, USA.
23
namespace GtkSharp.Generation {
29
public class StructField : FieldBase {
31
public static int bitfields;
33
public StructField (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
35
protected override string DefaultAccess {
51
result = Int32.Parse (elem.GetAttribute("array_len"));
53
Console.Write ("Non-numeric array_len: " + elem.GetAttribute("array_len"));
54
Console.WriteLine (" warning: array field {0} incorrectly generated", Name);
61
public new string CSType {
63
string type = base.CSType;
66
else if ((IsPointer || SymbolTable.Table.IsOpaque (CType)) && type != "string")
75
return (CName.StartsWith ("dummy") || CName.StartsWith ("padding"));
79
public bool IsPointer {
81
return (CType.EndsWith ("*") || CType.EndsWith ("pointer"));
85
public new string Name {
88
if ((IsPointer || SymbolTable.Table.IsOpaque (CType)) && CSType != "string")
90
result += SymbolTable.Table.MangleName (CName);
98
string studly = base.Name;
100
throw new Exception ("API file must be regenerated with a current version of the GAPI parser. It is incompatible with this version of the GAPI code generator.");
106
public override void Generate (GenerationInfo gen_info, string indent)
111
StreamWriter sw = gen_info.Writer;
112
SymbolTable table = SymbolTable.Table;
114
string wrapped = table.GetCSType (CType);
115
string wrapped_name = SymbolTable.Table.MangleName (CName);
116
IGeneratable gen = table [CType];
119
sw.WriteLine (indent + "[MarshalAs (UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
120
sw.WriteLine (indent + "{0} {1} {2};", Access, CSType, StudlyName);
121
} else if (IsBitfield) {
122
base.Generate (gen_info, indent);
123
} else if (gen is IAccessor) {
124
sw.WriteLine (indent + "private {0} {1};", gen.MarshalType, Name);
126
if (Access != "private") {
127
IAccessor acc = table [CType] as IAccessor;
128
sw.WriteLine (indent + Access + " " + wrapped + " " + StudlyName + " {");
129
acc.WriteAccessors (sw, indent + "\t", Name);
130
sw.WriteLine (indent + "}");
132
} else if (IsPointer && (gen is StructGen || gen is BoxedGen)) {
133
sw.WriteLine (indent + "private {0} {1};", CSType, Name);
135
if (Access != "private") {
136
sw.WriteLine (indent + Access + " " + wrapped + " " + wrapped_name + " {");
137
sw.WriteLine (indent + "\tget { return " + table.FromNativeReturn (CType, Name) + "; }");
138
sw.WriteLine (indent + "}");
140
} else if (IsPointer && CSType != "string") {
141
// FIXME: probably some fields here which should be visible.
142
sw.WriteLine (indent + "private {0} {1};", CSType, Name);
144
sw.WriteLine (indent + "{0} {1} {2};", Access, CSType, Access == "public" ? StudlyName : Name);