Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 397 lines (332 sloc) 8.106 kb
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
1 // GtkSharp.Generation.Parameters.cs - The Parameters Generation Class.
2 //
3 // Author: Mike Kestner <mkestner@speakeasy.net>
4 //
f96454a @mkestner 2004-06-25 Mike Kestner <mkestner@ximian.com>
mkestner authored
5 // Copyright (c) 2001-2003 Mike Kestner
6 // Copyright (c) 2004 Novell, Inc.
7 //
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.
11 //
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.
16 //
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.
21
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
22
23 namespace GtkSharp.Generation {
24
25 using System;
1a0892e @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
26 using System.Collections;
eea6465 2002-06-09 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
27 using System.IO;
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
28 using System.Xml;
29
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
30 public class Parameter {
31
32 private XmlElement elem;
33
34 public Parameter (XmlElement e)
35 {
36 elem = e;
37 }
38
38e7bde 2002-08-28 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
39 public string CType {
40 get {
3b1dd10 @mkestner 2002-10-10 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
41 string type = elem.GetAttribute("type");
42 if (type == "void*")
43 type = "gpointer";
44 return type;
38e7bde 2002-08-28 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
45 }
46 }
47
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
48 public string CSType {
49 get {
b6114fe @mkestner 2003-05-18 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
50 string cstype = SymbolTable.Table.GetCSType( elem.GetAttribute("type"));
3b1dd10 @mkestner 2002-10-10 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
51 if (cstype == "void")
52 cstype = "System.IntPtr";
6a16e09 @mkestner 2003-09-12 Mike Kestner <mkestner@ximian.com>
mkestner authored
53 if (IsArray) {
f61ac5c @mkestner 2003-12-03 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
54 if (IsParams)
55 cstype = "params " + cstype;
38e7bde 2002-08-28 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
56 cstype += "[]";
554450a @mkestner 2003-02-23 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
57 cstype = cstype.Replace ("ref ", "");
58 }
38e7bde 2002-08-28 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
59 return cstype;
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
60 }
61 }
62
bbf727c @mkestner 2003-06-14 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
63 public IGeneratable Generatable {
64 get {
65 return SymbolTable.Table[CType];
66 }
67 }
68
6a16e09 @mkestner 2003-09-12 Mike Kestner <mkestner@ximian.com>
mkestner authored
69 public bool IsArray {
70 get {
71 return elem.HasAttribute("array");
72 }
73 }
74
1a0892e @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
75 public bool IsEllipsis {
76 get {
77 return elem.HasAttribute("ellipsis");
78 }
79 }
80
62a858e @mkestner 2003-11-16 Mike Kestner <mkestner@ximian.com>
mkestner authored
81 public bool IsCount {
82 get {
83
84 if (Name.StartsWith("n_"))
85 switch (CSType) {
86 case "int":
87 case "uint":
88 case "long":
89 case "ulong":
90 case "short":
91 case "ushort":
92 return true;
93 default:
94 return false;
95 }
96 else
97 return false;
98 }
99 }
100
a7d8b64 * generator/Parameters.cs (Parameters.Validate): If the parameters
Dan Winship authored
101 public bool IsDestroyNotify {
102 get {
103 return CType == "GDestroyNotify";
104 }
105 }
106
554450a @mkestner 2003-02-23 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
107 public bool IsLength {
108 get {
5e5a570 @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
109
110 if (Name.EndsWith("len") || Name.EndsWith("length"))
111 switch (CSType) {
112 case "int":
113 case "uint":
114 case "long":
115 case "ulong":
116 case "short":
117 case "ushort":
118 return true;
119 default:
120 return false;
121 }
122 else
123 return false;
554450a @mkestner 2003-02-23 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
124 }
125 }
126
f61ac5c @mkestner 2003-12-03 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
127 public bool IsParams {
128 get {
129 return elem.HasAttribute("params");
130 }
131 }
132
554450a @mkestner 2003-02-23 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
133 public bool IsString {
134 get {
135 return (CSType == "string");
136 }
137 }
138
6a16e09 @mkestner 2003-09-12 Mike Kestner <mkestner@ximian.com>
mkestner authored
139 public bool IsUserData {
140 get {
f61ac5c @mkestner 2003-12-03 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
141 return CSType == "IntPtr" && (Name.EndsWith ("data") || Name.EndsWith ("data_or_owner"));
6a16e09 @mkestner 2003-09-12 Mike Kestner <mkestner@ximian.com>
mkestner authored
142 }
143 }
144
71b46ec @mkestner 2002-08-03 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
145 public string MarshalType {
146 get {
b6114fe @mkestner 2003-05-18 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
147 string type = SymbolTable.Table.GetMarshalType( elem.GetAttribute("type"));
3b1dd10 @mkestner 2002-10-10 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
148 if (type == "void")
149 type = "System.IntPtr";
6a16e09 @mkestner 2003-09-12 Mike Kestner <mkestner@ximian.com>
mkestner authored
150 if (IsArray) {
554450a @mkestner 2003-02-23 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
151 type += "[]";
152 type = type.Replace ("ref ", "");
153 }
3b1dd10 @mkestner 2002-10-10 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
154 return type;
71b46ec @mkestner 2002-08-03 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
155 }
156 }
157
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
158 public string Name {
159 get {
f7ba4e2 * generator/Parameters.cs:
Martin Willemoes Hansen authored
160 return SymbolTable.Table.MangleName (elem.GetAttribute("name"));
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
161 }
162 }
163
c9f1ead @mkestner 2004-05-07 Mike Kestner <mkestner@ximian.com>
mkestner authored
164 public string PropertyName {
165 get {
166 return elem.GetAttribute("property_name");
167 }
168 }
169
bbf727c @mkestner 2003-06-14 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
170 public string PassAs {
171 get {
bdc5c70 @mkestner 2003-10-13 Mike Kestner <mkestner@ximian.com>
mkestner authored
172 if (elem.HasAttribute ("pass_as"))
173 return elem.GetAttribute ("pass_as");
174
bf9ed95 @mkestner 2004-12-27 Mike Kestner <mkestner@novell.com>
mkestner authored
175 if (IsArray || CSType.EndsWith ("IntPtr"))
bdc5c70 @mkestner 2003-10-13 Mike Kestner <mkestner@ximian.com>
mkestner authored
176 return "";
177
bf9ed95 @mkestner 2004-12-27 Mike Kestner <mkestner@novell.com>
mkestner authored
178 if (CType.EndsWith ("*") && (Generatable is SimpleGen || Generatable is EnumGen))
c62e9ab @mkestner 2003-10-17 Mike Kestner <mkestner@ximian.com>
mkestner authored
179 return "out";
180
bdc5c70 @mkestner 2003-10-13 Mike Kestner <mkestner@ximian.com>
mkestner authored
181 return "";
bbf727c @mkestner 2003-06-14 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
182 }
183 }
184
a7d8b64 * generator/Parameters.cs (Parameters.Validate): If the parameters
Dan Winship authored
185 string scope;
96f81cf @mkestner 2005-04-04 Mike Kestner <mkestner@novell.com>
mkestner authored
186 public string Scope {
187 get {
a7d8b64 * generator/Parameters.cs (Parameters.Validate): If the parameters
Dan Winship authored
188 if (scope == null)
189 scope = elem.GetAttribute ("scope");
190 return scope;
191 }
192 set {
193 scope = value;
96f81cf @mkestner 2005-04-04 Mike Kestner <mkestner@novell.com>
mkestner authored
194 }
195 }
196
f61ac5c @mkestner 2003-12-03 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
197 public string CallByName (string call_parm_name)
198 {
199 string call_parm;
200 if (Generatable is CallbackGen)
201 call_parm = SymbolTable.Table.CallByName (CType, call_parm_name + "_wrapper");
202 else
203 call_parm = SymbolTable.Table.CallByName(CType, call_parm_name);
204
205 if (IsArray)
206 call_parm = call_parm.Replace ("ref ", "");
207
208 return call_parm;
209
210 }
211
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
212 public string StudlyName {
213 get {
214 string name = elem.GetAttribute("name");
215 string[] segs = name.Split('_');
216 string studly = "";
217 foreach (string s in segs) {
90705a1 @mkestner 2003-07-14 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
218 if (s.Trim () == "")
219 continue;
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
220 studly += (s.Substring(0,1).ToUpper() + s.Substring(1));
221 }
222 return studly;
223
224 }
225 }
226 }
227
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
228 public class Parameters : IEnumerable {
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
229
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
230 ArrayList param_list = new ArrayList ();
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
231
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
232 public Parameters (XmlElement elem) {
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
233
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
234 if (elem == null)
235 return;
236
1a0892e @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
237 foreach (XmlNode node in elem.ChildNodes) {
238 XmlElement parm = node as XmlElement;
239 if (parm != null && parm.Name == "parameter")
240 param_list.Add (new Parameter (parm));
241 }
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
242 }
243
1a0892e @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
244 public int Count {
245 get {
246 return param_list.Count;
247 }
248 }
249
b7e4cc5 * generator/Parameters.cs (IsHidden): method to check if a
Dan Winship authored
250 public int VisibleCount {
251 get {
252 int visible = 0;
253 foreach (Parameter p in this) {
254 if (!IsHidden (p))
255 visible++;
256 }
257 return visible;
258 }
259 }
260
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
261 public Parameter this [int idx] {
262 get {
1a0892e @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
263 return param_list [idx] as Parameter;
8b85bf6 @mkestner 2002-07-16 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
264 }
265 }
266
b7e4cc5 * generator/Parameters.cs (IsHidden): method to check if a
Dan Winship authored
267 public bool IsHidden (Parameter p)
268 {
269 int idx = param_list.IndexOf (p);
270
271 if (idx > 0 && p.IsLength && this [idx - 1].IsString)
272 return true;
273
274 if (p.IsCount && ((idx > 0 && this [idx - 1].IsArray) ||
275 (idx < Count - 1 && this [idx + 1].IsArray)))
276 return true;
277
278 if (p.CType == "GError**")
279 return true;
280
281 if (HasCB || HideData) {
282 if (p.IsUserData && (idx == Count - 1))
6bf7376 * parser/gapi2xml.pl (addParamsElem): change the handling of
Dan Winship authored
283 return true;
284 if (p.IsUserData && idx > 0 &&
285 this [idx - 1].Generatable is CallbackGen)
a7d8b64 * generator/Parameters.cs (Parameters.Validate): If the parameters
Dan Winship authored
286 return true;
287 if (p.IsDestroyNotify && (idx == Count - 1) &&
288 this [idx - 1].IsUserData)
289 return true;
b7e4cc5 * generator/Parameters.cs (IsHidden): method to check if a
Dan Winship authored
290 }
291
292 return false;
293 }
294
295 bool has_cb;
296 public bool HasCB {
297 get { return has_cb; }
298 set { has_cb = value; }
299 }
300
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
301 bool hide_data;
38e7bde 2002-08-28 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
302 public bool HideData {
303 get { return hide_data; }
304 set { hide_data = value; }
305 }
306
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
307 bool is_static;
3821938 @gonzalop 2003-04-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
gonzalop authored
308 public bool Static {
f61ac5c @mkestner 2003-12-03 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
309 get { return is_static; }
3821938 @gonzalop 2003-04-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
gonzalop authored
310 set { is_static = value; }
311 }
312
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
313 bool cleared = false;
314 void Clear ()
315 {
316 cleared = true;
317 param_list.Clear ();
318 }
319
320 public IEnumerator GetEnumerator ()
321 {
322 return param_list.GetEnumerator ();
323 }
324
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
325 public bool Validate ()
326 {
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
327 if (cleared)
328 return false;
329
a7d8b64 * generator/Parameters.cs (Parameters.Validate): If the parameters
Dan Winship authored
330 for (int i = 0; i < param_list.Count; i++) {
331 Parameter p = this [i];
1a0892e @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
332
333 if (p.IsEllipsis) {
d837953 @mkestner 2002-07-20 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
334 Console.Write("Ellipsis parameter ");
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
335 Clear ();
336
d837953 @mkestner 2002-07-20 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
337 return false;
338 }
339
554450a @mkestner 2003-02-23 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
340 if ((p.CSType == "") || (p.Name == "") ||
b6114fe @mkestner 2003-05-18 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
341 (p.MarshalType == "") || (SymbolTable.Table.CallByName(p.CType, p.Name) == "")) {
554450a @mkestner 2003-02-23 Mike Kestner <mkestner@speakeasy.net>
mkestner authored
342 Console.Write("Name: " + p.Name + " Type: " + p.CType + " ");
33cb5d8 @mkestner 2005-01-26 Mike Kestner <mkestner@novell.com>
mkestner authored
343 Clear ();
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
344 return false;
345 }
b7e4cc5 * generator/Parameters.cs (IsHidden): method to check if a
Dan Winship authored
346
a7d8b64 * generator/Parameters.cs (Parameters.Validate): If the parameters
Dan Winship authored
347 if (p.Generatable is CallbackGen) {
b7e4cc5 * generator/Parameters.cs (IsHidden): method to check if a
Dan Winship authored
348 has_cb = true;
a7d8b64 * generator/Parameters.cs (Parameters.Validate): If the parameters
Dan Winship authored
349 if (i == Count - 3 &&
350 this [i + 1].IsUserData &&
351 this [i + 2].IsDestroyNotify)
352 p.Scope = "notified";
353 }
6857128 2002-06-21 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
354 }
355
356 return true;
357 }
358
eea6465 2002-06-09 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
359 public bool IsAccessor {
360 get {
b7e4cc5 * generator/Parameters.cs (IsHidden): method to check if a
Dan Winship authored
361 return VisibleCount == 1 && AccessorParam.PassAs == "out";
362 }
363 }
364
365 public Parameter AccessorParam {
366 get {
367 foreach (Parameter p in this) {
368 if (!IsHidden (p))
369 return p;
370 }
371 return null;
eea6465 2002-06-09 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
372 }
373 }
374
375 public string AccessorReturnType {
376 get {
b7e4cc5 * generator/Parameters.cs (IsHidden): method to check if a
Dan Winship authored
377 Parameter p = AccessorParam;
378 if (p != null)
379 return p.CSType;
1a0892e @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
380 else
381 return null;
eea6465 2002-06-09 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
382 }
383 }
384
385 public string AccessorName {
386 get {
b7e4cc5 * generator/Parameters.cs (IsHidden): method to check if a
Dan Winship authored
387 Parameter p = AccessorParam;
388 if (p != null)
389 return p.Name;
1a0892e @mkestner 2003-09-11 Mike Kestner <mkestner@ximian.com>
mkestner authored
390 else
391 return null;
eea6465 2002-06-09 Rachel Hestilow <hestilow@ximian.com>
Rachel Hestilow authored
392 }
393 }
6d30cf0 @mkestner refactoring to remove substantial code duplication thoughout the generat...
mkestner authored
394 }
395 }
396
Something went wrong with that request. Please try again.